Process Management in Linux Operating System
Process management is a case in point. Linux creates a process whenever a program is launched, either by you or by Linux. This process is a container of information about how that program is running and what’s happening.
If the process runs and terminates correctly, then everything is hunky-dory; however, if it hogs the CPU, or refuses to go when its time is up, then the Linux commands may help you to restore law and order.
Let’s start with a list of things you may want to do when managing Linux processes:
-> See which processes are running.
-> See how much of your Linux system the processes are using (especially any greedy ones).
-> Locate a particular process to see what it’s doing or to take action on it.
-> Define or change the level of priority associated with that process.
-> Terminate the process if it has outlived its usefulness or if it’s misbehaving.
-> When you execute a program on your linux system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.
Whenever you issue a command in linux, it creates, or starts, a new process. When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program.
The operating system tracks processes through a five-digit ID number known as the pid or the process ID. Each process in the system has a unique pid.
-> There are 2 ways we can starts a process:-
1. Foreground - ProcessBy default, every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen.
You can see this happen with the ls command. If you wish to list all the files in your current directory, we can use the following command:-
$ls ch*.doc
-> While a program is running in the foreground and is time-consuming, no other commands can be run (start any other processes) because the prompt would not be available until the program finishes processing and comes out.
2. Background - Process
A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits.
The advantage of running a process in the background is that you can run other commands; you do not have to wait until it completes to start another!
The simplest way to start a background process is to add an ampersand (&) at the end of the command.
$ls ch*.doc &
Listing Running Processes
It is easy to see your own processes by running the ps (process status) command as follows:-
Stopping Processes
Ending a process can be done in several different ways. Often, from a console-based command, sending a CTRL + C keystroke (the default interrupt character) will exit the command. This works when the process is running in the foreground mode.
If a process is running in the background, you should get its Job ID using the ps command. After that, you can use the kill command to kill the process as follows −
$kill 6758
Terminated
Parent and Child Processes
Each unix process has two ID numbers assigned to it: The Process ID (pid) and the Parent process ID (ppid). Each user process in the system has a parent process.
Most of the commands that you run have the shell as their parent. Check the ps -f example where this command listed both the process ID and the parent process ID.
The top Command
The top command is a very useful tool for quickly showing processes sorted by various criteria.
It is an interactive diagnostic tool that updates frequently and shows information about physical and virtual memory, CPU usage, load averages, and your busy processes.
Here is the simple syntax to run top command and to see the statistics of CPU utilization by different processes −
$top
Job ID Versus Process ID
Background and suspended processes are usually manipulated via job number (job ID). This number is different from the process ID and is used because it is shorter.
In addition, a job can consist of multiple processes running in a series or at the same time, in parallel. Using the job ID is easier than tracking individual processes.
Process management is a case in point. Linux creates a process whenever a program is launched, either by you or by Linux. This process is a container of information about how that program is running and what’s happening.
If the process runs and terminates correctly, then everything is hunky-dory; however, if it hogs the CPU, or refuses to go when its time is up, then the Linux commands may help you to restore law and order.
Let’s start with a list of things you may want to do when managing Linux processes:
-> See which processes are running.
-> See how much of your Linux system the processes are using (especially any greedy ones).
-> Locate a particular process to see what it’s doing or to take action on it.
-> Define or change the level of priority associated with that process.
-> Terminate the process if it has outlived its usefulness or if it’s misbehaving.
-> When you execute a program on your linux system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.
Whenever you issue a command in linux, it creates, or starts, a new process. When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program.
The operating system tracks processes through a five-digit ID number known as the pid or the process ID. Each process in the system has a unique pid.
-> There are 2 ways we can starts a process:-
1. Foreground - ProcessBy default, every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen.
You can see this happen with the ls command. If you wish to list all the files in your current directory, we can use the following command:-
$ls ch*.doc
-> While a program is running in the foreground and is time-consuming, no other commands can be run (start any other processes) because the prompt would not be available until the program finishes processing and comes out.
2. Background - Process
A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits.
The advantage of running a process in the background is that you can run other commands; you do not have to wait until it completes to start another!
The simplest way to start a background process is to add an ampersand (&) at the end of the command.
$ls ch*.doc &
Listing Running Processes
It is easy to see your own processes by running the ps (process status) command as follows:-
PID TTY TIME CMD
2541 pts/0 00:00:00 bash
2581 pts/0 00:00:00 ps
|
Stopping Processes
Ending a process can be done in several different ways. Often, from a console-based command, sending a CTRL + C keystroke (the default interrupt character) will exit the command. This works when the process is running in the foreground mode.
If a process is running in the background, you should get its Job ID using the ps command. After that, you can use the kill command to kill the process as follows −
$kill 6758
Terminated
Parent and Child Processes
Each unix process has two ID numbers assigned to it: The Process ID (pid) and the Parent process ID (ppid). Each user process in the system has a parent process.
Most of the commands that you run have the shell as their parent. Check the ps -f example where this command listed both the process ID and the parent process ID.
The top Command
The top command is a very useful tool for quickly showing processes sorted by various criteria.
It is an interactive diagnostic tool that updates frequently and shows information about physical and virtual memory, CPU usage, load averages, and your busy processes.
Here is the simple syntax to run top command and to see the statistics of CPU utilization by different processes −
$top
Job ID Versus Process ID
Background and suspended processes are usually manipulated via job number (job ID). This number is different from the process ID and is used because it is shorter.
In addition, a job can consist of multiple processes running in a series or at the same time, in parallel. Using the job ID is easier than tracking individual processes.