![]() |
The PID (process identification number) is a serial number (starting from 1) given by the operating system to uniquely identify the process. Every process started either by the operating system or by the user gets a PID in order of their invocation by the kernel. If we start the same process several times, it will be assigned different PID numbers each time. Every process gets some memory allocated to it and CPU usage based on its priority. Note: For a better understanding you can go through these Processes, Shell Function Library topics also. The first process started by the kernel is the init process which consequently gets a process ID of 1. All the PIDs are visible/displayed in the process table. The types of processes we see in the process table are:
Foreground Processes
Start a foreground process say xlogo. Install it if it’s not present by: sudo apt install x11-apps
1. ps commandThe ps command prints the snapshot of processes currently running/paused by the shell. The first column gives us the PID and shows the command which started that particular process. ps
![]()
2. jobs commandAlthough the jobs command shows us the jobspec of the process started by the terminal, combining it with option -l shows the PID as well. jobs -l
![]()
3. pgrep commandThe pgrep command only prints the PID of the process. The argument of this command is the process name whose PID we want to print. pgrep [processName]
![]()
4. pidof commandThe pidof command prints the PID of the processes. The argument should be the process name pidof [processName]
![]()
Background Processes
$ process_name &
$ /full/path/to/process_name &
1. ps commandTo view the processes in the background started by the terminal, write ps
![]()
To view all processes regardless of what terminal (or no terminal) they are controlled by, use option -e ps -e
![]()
We can pipe the output to grep to view the PID of specific processes. ps -e | grep -i 'pattern'
![]()
To view the PIDs of processes started by a particular user ps -u [user]
![]()
2. jobs commandjobs with option -l shows the PID of processes run by the terminal. jobs -l
![]()
3. pgrep commandIt prints only the PID of the process. The argument is the process name. pgrep [processName]
![]()
To view the PIDs of processes started by a particular user pgrep -u [user] [processName]
![]()
4. pidof commandThe pidof command prints the PID of the processes. The argument should be the process name. It is similar to pidof command. pidof [arg]
![]()
5. top commandThe top command displays current processes in real-time. The PID of the processes is displayed as well. top
![]()
Coupling the top command with option -u allows us to view processes started by a particular user. top -u [user]
ConclusionIn this article we discussed about `ps` command in Linux which is used to show all processes, we also discussed few options available and understand about `jobs` which displays the PID of terminal-run processes, `pgrep` and `pidof` use to find the PID of specific processes, and `top` gives real-time process monitoring. Overall, we can say that these commands offer convenient ways to analyze and control background processes. |
Reffered: https://www.geeksforgeeks.org
Linux Unix |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |