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 the ps command.
A process runs in the operating in two ways: i) foreground process or ii) 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 a screen as the output device. But a process can be run in the background and input-output can be redirected.
For example, if you run the 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 the output.txt file. The content of the file is shown below using the cat command.
Background Process
When a process runs as a background process, the process is not connected to the keyboard. Hence, to run other processes, you don't need to wait to complete the process. In the most straightforward way, we can run a background process by using & after the command.
Let us discuss this 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, which 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 pid of the process, then we can use the kill -9 pid command.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.