Whenever you give a command in any operating system, the process starts. In Linux, when the process starts a five-digit number is created which is called process id or PID. This is a system-generated unique Id given for the process.
With the help of the PID, we can track the process and two processes won't have the same process IDs.
A process executes in two ways they are,
Every process by default runs in Foreground which means the output is printed on the screen.
The best example for the foreground process is the ls command which prints the output on the screen by listing the files and directories.
When a program is running in the foreground, we can not start another process without completing the previous process. It is because of this reason foreground process is considered a time-consuming process.
When a process starts running and it is not visible on the screen it is called a background process. You can simultaneously run the 'n' number of commands in the background process.
To enable the background process you have to provide the ampersand symbol (&) at the end of the command.
Whenever the process is completed and then you hit enter you will get a prompt like the below snippet, which means the background process is completed successfully.
 + Done ls & $
ps command is used to track or to list all the running processes.
PID TTY TIME CMD 19 pts/1 00:00:00 ls 24 pts/1 00:00:00 ps
If you require more information about the process you can use the
ps command along with the -f option.
$ ps –f
UID PID PPID C STIME TTY TIME CMD 52471 19 1 0 07:20 pts/1 00:00:00f ls 52471 25 19 0 08:04 pts/1 00:00:00 ps -f
To get more information about a particular process, you can give the ps command along with the PID.
$ ps 19
PID TTY TIME CMD 19 pts/1 00:00:00 ls
The information provided by the ps command for the process are :
When a process runs in the foreground, you can interrupt the process by hitting Ctrl+c. When a process runs in the background the
kill command is used along with the process id to interrupt or to stop the running process.
$ kill 19
Output: The process which has the process id 19 is terminated.
Sometimes a process cannot be terminated by using the kill command. To terminate such kind of process uses the below command.
$ kill -9 pid
-9 forces the termination of the process by blocking the signals.
$ kill -9 19
The below command is used to get the list of jobs that are either running or stopped.
bg command is used to resume the suspended jobs and runs them in the background.
bg [ %job ]
fg command is used to start the job which has already stopped in the foreground.
fg [ job_id ]
top command is used to show all the running processes within the working environment of Linux.
Press 'q' on the keyboard to move out of the process display.
|PID||The process ID of each task|
|User||The username of the task owner|
|PR||Priority Can be -20(highest) or 19(lowest)|
|NI||The nice value of a task|
|VIRT||Virtual memory used (kb)|
|RES||Physical memory used (kb)|
|SHR||Shared memory used (kb)|
Status of the process.
|%CPU||% of CPU time|
|%MEM||Physical memory used|
|TIME+||Total CPU time|
nice command starts a new process (job) and assigns it a priority (nice) value for the process. The nice value ranges from -20 to 19, where -20 is of the highest priority and 19 is of the lowest priority
nice [-nice value]
renice command is used to change the priority of the running process.
renice [-nice value] [process id]
df command shows the disk information of the Linux file systems.
Filesystem 1K-blocks Used Available Use% Mounted on /dev/loop0 1845236 15246876 2554440 86% / none 4 0 4 0% /sys/fs/task udev 452369 4 493808 1% /dev tmpfs 195263 1364 99308 2% /run none 2123 0 5120 0% /run/lock none 421980 1764 501588 1% /run/shm none 562831 20 102380 1% /run/user /dev/sda3 158297648 164417964 10348112 95% /host
free command shows the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel
total used free shared buffers cached Mem: 1006708 935872 70836 0 148244 346656 -/+ buffers/cache: 440972 565736 Swap: 262140 130084 132056