Home Linux Commandline Tools Differences Between PID, TID and PPID in Linux

Differences Between PID, TID and PPID in Linux

A Linux operating system provides the perfect environmental exposure for users to understand the Ins and Outs of process management. The simplest definition of a process is any program in execution (running).

For instance, the web browser you are using to read this article piece only becomes a process once that web browser is up and running. Before your web browser was installed and launched, it only existed as a program (a process in waiting).

When you dive deeper into the concept of process management, you will get to acknowledge the various properties associated with processes. This article will walk us through differentiating three processes’ properties namely: PID, TID, and PPID.

Background Information on Process Management

In order to distinctively understand and differentiate the processes mentioned above’ properties, we need to understand process management from a parallel computing perspective.

In parallel computing, allocated and purpose-driven resources such as file descriptors and memory space qualify as a valid definition of a process.

Most minor instructions set associated with and manipulated by processes are called threads. A scheduler handles these threads.

  • Multithreading and multiprocessing are parallel computing concepts since these programming techniques support the simultaneous performance of multiple operations.
  • Under multithreading, a scheduler assigns different tasks to multiple threads associated with a single process. The memory resources allocated to this single process are therefore shared among multiple threads present.
  • Under multiprocessing, a single parent process is associated with multiple child processes. Here, process communication is not as efficient as thread communication when sharing resources hence the need for explicit declaration.

Defining PID, TID, and PPID

By default, these three highlighted process properties are identifiers. Let us define them one by one.

  • PID (Process Identifier) – Every running process accounted for by the system kernel is identified by a unique number called the process identifier. The systemd is associated with PID 1.
  • TID (Thread Identifier) – This number (integer) uniquely identifies threads associated with a process or processes. When there is only one thread; like in the case of serial programming, TID and PID become indistinguishable. TID is only different from PID in multi-thread environments since each thread is assigned a unique TID. Also, note that threads attached to the same process share the PID.
  • PPID (Parent Process Identifier) – When a multiprocessing sequence is triggered by a program, a parent process comes into existence which then (the parent process) consequently initiates/facilitates the creation of numerous child processes. PPID uniquely identifies the parent process. The child processes share the PPID but will have different and unique PIDs. PPID helps link child processes to their associated parent process.

Getting a Known Process PID in Linux

The command pidof helps us identify the PID associated with a named process. For instance, we can query the PID associated with a running Brave web browser.

$ pidof brave
Get Process PID in Linux
Get Process PID in Linux

The output implies that this process is associated with numerous PIDs.

Getting a Known PID’s TIDs

There are two approaches to achieving this objective:

1. Querying /proc/PID/task File

Let us take a PID from the execution of the above pidof command.

$ ls /proc/3410/task 
Get Process TIDs Linux
Get Process TIDs Linux

The /proc/… directory accounts for each running process based on its PID and the …/task directory accounts for the TIDs associated with each PID. As you might have noted, the TID value will either be equal to/greater than the PID value.

2. Using ps Command

Here, we use the ps command together with the --pid and tid flags.

$ ps --pid 3410 -O tid,lwp,nlwp -L
List Process TIDs Linux
List Process TIDs Linux

LWP denotes Light Weight Process and NLWP counts them.

Getting a Known TID’s PID

The first approach is to query the /proc/… directory using the readlink command. You have to specify the TID number in the command.

$ readlink -f /proc/*/task/4346 | cut -d/ -f3
Query Proc Directory
Query Proc Directory

Alternatively, the ps command should also work. We however need to pipe its query to an awk command for it to print to the standard output the queried info.

$ ps -e -O tid -L | awk '$2 == 4346'
Query Process Info Linux
Query Process Info Linux

Getting a Known PID’s PPID

We can reference the /proc/PID/status directory using the cat command and then pipe the results to the grep command which then retrieves the PID’s PPID.

$ cat /proc/3389/status | grep PPid

The ps command can also retrieve a PID’s PPID where the -O flag redirects the retrieved PPID as output.

$ ps --pid 3389 -O ppid
Get Process PIDs PPID in Linux
Get Process PIDs PPID in Linux

Getting a Known PPID’s PIDs

Here, we use the ps command with the -O flag which makes it possible to print out the PID and PPID columns side by side.

$ ps --ppid 2747 -O ppid
Get Process PPIDs PIDs in Linux
Get Process PPIDs PIDs in Linux

In this article, we have differentiated PID, TID, and PPID identifiers and also shown various command-line approaches to retrieving their respective values. Hope you enjoyed the article and feel free to leave a comment or feedback.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.