Process management in Linux

If you are working with Linux in text-mode, it is vital to know how to manage processes, terminate them, prioritize them, etc. In addition, process management is more crucial for system administrators which mostly manage servers. For example, they need to terminate the process which is in infinite loop in order to avoid system to hang.

Fortunately, Linux is really rich in this area since it multi-tasks and multi-threads OS. Furthermore, Linux is Unix-like OS which is server based OS, therefore, it should facilitates system administrators to manage processes and tasks.

This post briefly talks about some basics and primary process management commands in Linux.

At first we need a command(s) to show the current running processes on the system. The best and first command to monitor current processes in the system is “top”. This command shows CPU, RAM usage and process ID of each process. Additionally, it monitors the situation of available process lively and updates automatically. It comes with numerous options which you can find more about them in the man page of “top” command. If you do not want to use “top” command, other command is also available to monitor the running process of the system. “ps” command almost does the same task of “top” with less options. If you type “ps” on the command line it just returns PID of “bash” and “ps” which is not true. If you want to list all running processes of the system, type the following command,

$ ps -aux

For getting list of the processes which are running by especial user, type the following command,

$ ps -u root

You can replace “root” with user(s) account name(s).

If you know the name of the process and want to get PID of it, you can use “pidof” command which returns PID of the given process. Look at the following example,

$ pidof bash

Bear in mind that if you give wrong process name or non-existed name, the command will not prompts error and it just shows empty line.

For killing an especial process firstly you need to know PID of the process and then terminate the process with “kill” command. Look at the example,

$ kill 14062

On the condition that the user types wrong PID, the command shows “No such process” error.

If you want to run a process in background just add “&” sign after your command like below,

$ mpg123 *.mp3 &

After that, the process will run on background and you can do other tasks. If the process was not redirected to background, just press CTRL+Z. Even if you forgot to add “&” sign after process, you can send the process to background with just pressing CTRL+Z easily.

For getting the list of the process which are running on background just type “bg”.

In order, to bring process from background to foreground type “fg”. It will bring the last process to foreground which you sent to background. For bring an especial process to foreground, firstly you need to get the number of process running on background, then type that number in front of “fg” command like below,

$ fg 1

The above command brings first process sent to background. If you want to send the process again to background just press CTRL+Z.

This post was just a short introduction to the process management and in the next and later post I will discuss more about process management in Linux.

For getting more information read man pages of mentioned commands.

send your idea and information to kasra.madadipouya@geeksweb.tk

Leave a Reply