Process Management on Linux

0
1412

In Linux system every time we start any new program or run a command on the terminal it starts a new process. These processes, all are unique and identified by PID(Process identification) number. Process management is an important task for Linux administrator. It can be helpful to monitor and optimize system performance.
The processes are mainly two types such as foreground processes or foreground jobs and background processes or background jobs.
By default, any program or command on Linux machine starts as a foreground process. For many processes, it doesn’t matter because it takes a little time i.e Milliseconds. Sometimes it will be helpful to start process in the background. Because some processes will take a long time to complete.
Use & at the end of the command line will make the process starts in background immediately. The combination of Ctrl and z(Ctrl+z) keys stops a job temporarily and move it to the background. Ctrl+c can be used to cancel the current interactive process. bg command can be used to send the process to background. fg command can be helpful to move the process from background to foreground. Ctrl+d can be used to stop the process by sending the EOF character to process. Jobs command can be used to display the currently running process stats.

In the above example first we run command vimabc.txt and stooped with by ctrl+z and move to Background by using bg command. After that started the process vi xyz.txt and moved to background process like first one. We can check it by using jobs command. By using fg command we can move the last background job to foreground process and close it.

ps

PS stands for process status. It displays output related to the current running jobs. It produces different types of output, depends on the arguments or options.

Ps ef command can be useful to get the information about the current running commands. Ps fax displays the hierarchical information about the processes.

Kill:

Kill command can be used to terminate the processes. But PID is required to terminate the particular process.We can get the pid of the process by using ps command. We can get the pod of particular service by using the pidof command. Pgrep also works for it.


We can terminate all process by using kill all command.


Linux is a Multiprocessing system. So the number of processes are running at a time in the linux system. Which slows down the system performance. To avoid this we can customize the priority of processes as per the process requirements. This priority is called as nice. By default, all the processes have the same priority. The default nice value is zero. Nice value range from -20 to 19. The lower values the higher priority. We can start a process with a custom nice value as follows

# nice -n -6 /usr/sbin/sshd

After we can also change the nice value by using renice command.

#renice -9 -p 7689

Top
Top command displays the real-time stats for the current processes.