Get Process ID of Linux Foreground and Background Processes
Last Updated :
23 Jul, 2025
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: These processes are user dependent. If the foreground processes are run from the terminal, the shell prompt remains unavailable and will be available only when the foreground process is terminated or stopped.
- Background Processes: These processes are usually run independently from the user. If a background process is started from a terminal by the user, the shell prompt remains available. One must append & a symbol after the process name in the terminal to start it in the background.
- Daemon Processes: These are system processes started by the root and they keep running in the background until the system shuts down.
- Zombie Processes: These are dead/terminated processes that still exist in the process table and have a PID despite having no resources allocated to them.
Foreground Processes
- When we start a foreground process from the terminal, the shell prompt is unavailable to the user.
- To get back the shell prompt, press Ctrl+Z which sends a STOP signal to the process.
- The process stops and the shell prompt is now available to execute the commands to view the PID of that foreground process.
Start a foreground process say xlogo. Install it if it's not present by:
sudo apt install x11-apps

1. ps command
The 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 command
Although 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 command
The 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 command
The pidof command prints the PID of the processes. The argument should be the process name
pidof [processName]
Background Processes
- Some background processes are started in the shell by the user while some of them are by the kernel without any user intervention.
- To start a background process from the terminal, write the process name(if its address is not stored in the PATH variable, then you have to give its full absolute or relative address) and append the & symbol at the end.
$ process_name &
$ /full/path/to/process_name &
1. ps command
To 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 command
jobs with option -l shows the PID of processes run by the terminal.
jobs -l
3. pgrep command
It 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 command
The 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 command
The 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]

Conclusion
In 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.
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Linux/Unix Tutorial Linux is one of the most widely used open-source operating systems. It's fast, secure, stable, and powers everything from smartphones and servers to cloud platforms and IoT devices. Linux is especially popular among developers, system administrators, and DevOps professionals.Linux is:A Unix-like OS
10 min read
Linux Commands Cheat Sheet Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read
Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are
10 min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read
25 Basic Linux Commands For Beginners [2025] While performing a task, we all need shortcuts. Shortcuts help us to complete a task quickly. Linux comes with such commands which are one to two words, using that commands, you can perform several operations in no time. As a beginner, you must be aware of those basic Linux commands to complete an o
13 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read