Working with Processes in Linux Environment - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Working with Processes in Linux Environment

Share This
Each process in an operating system has a unique id. The operating system tracks processes by this id, known as PID. If you want to check processes in your system, you can run ps command.

A process runs in the operating as in two ways: foreground process or background process.

Foreground Process

If you run a process, by default the process runs in the foreground and it interacts with the keyboard as the input device and with the screen as an output device. But a process can be run in the background and input-output can be redirected.

For example, if you run ps command, a list of files will be shown on the screen. This process runs in the foreground and communicates with the screen as an output device.

To redirect the output to a file, output.txt, you can run the command as ls >> output.txt. Here, instead of printing the output on the screen, the output will be redirected to output.txt file. The content of the file is shown below using cat command. 

Background Process

When a process runs as a background process, the process is not connected to the keyboard. Hence to run another process, you don't need to wait for the completion of the process. In the simplest way, we can run a background process by using & after the command.

Let us discuss with an example. In the previous program, instead of ls, you should run ls &

Listing Running Process

The command ps is used to show the status of processes currently running in the system. Only those processes are enlisted, that are running for the current user. 

To get more detailed information about processes, we can use some of the options like ps -aux. Here, -a stands for listing the processes of all the users. The option -u is used to print detailed information about the running processes and -x enforces to list those processes, which has no controlling terminal. 

Killing a Process

Sometimes, we may need to kill a process because it may consume huge memory or cpu clocks, or it may not be needed anymore. Hence, first, we need to determine the PID of the process, then we can use kill -9 pid command.

Happy Exploring!

No comments:

Post a Comment