A process is an instance of a program currently running in the form of thread(s). Depending on the environment, a process can be uni-threaded (comprising of a single thread) or multithreaded (comprising of multiple threads). A process is an active entity as opposed to a program which is a passive entity.
In Linux, there are various commands which are used for process manipulation. There are commands which enable the user to view the list of processes and their information, commands which allow the user to delay the start of a particular process and commands which terminate or stop a process from further execution. These commands enable the user to manipulate running processes according to his/her needs. All these commands have many options that can be used along with them.
A few commands that are used for process manipulation are:
1. ps - The ps command is used to list all the currently running processes in the system and information related to them. This information consists of the process name, user, memory consumption, CPU consumption, process ID, etc.
2. sleep - The sleep command is used in Linux to delay a running program by a certain amount of time. The amount of time to be delays can be specified in seconds, minutes, hours, and even days. The suffix values for minutes, hours days are m, h, and d respectively. If no suffix value is specified, then, by default, the value is taken in seconds.
If during the sleep period, you hit Ctrl+Z, then the sleep is terminated and the process continues execution.
3. jobs - The jobs command in Linux is used to list the status of all the jobs currently running in the terminal along with their job number. This lists only those processes which started running in this session. Job numbers always start from 1 and are always displayed inside .
There are various options that can be used along with the jobs command such as -n (displays processes whose status has changed after the previous check), -p (lists only the process IDs), etc.
4. bg - The bg command is used to push a suspended process into the background where it can continue to run. The syntax for this command is bg %n where n is the job number of the suspended process the user wants to push to the background.
5. fg - Similar to the bg command, the fg command is used to bring back a suspended process in the background to the foreground. The syntax for this command is fg %n where n is the job number of the suspended process the user wants to push to the background. To kill a process running in the foreground, Ctrl + C can be used.
6. kill - The kill command in Linux is used to kill or stop a currently running process. The kill command can be used both with the job number and the Process ID (or PID).
The syntax to kill a process with its job number is kill %n where n is the job number.
The syntax to kill a process with its Process ID is kill -9 n where n is the Process ID.
This command also has many options that can be used along with it.