What is ppid in linux

How to Find the PID and PPID of a Process in Linux

Knowing the PID and PPID of a process can be helpful if you need to manage or interact with a process running on your system.

There are numerous ways to get the PID (Process ID) and PPID (Parent Process ID) of a given process in Linux.

Command Description
pidof process_name Works with exact process name
pgrep process_name Returns PID of all matches
ps -o ppid= -p PID Get the PPID from PID
$$ PID of current process/shell
$ PID of current process’s parent

I’ll explain these commands in detail but before that a quick recap of process, PID and PPID.

Linux process basics

Everything that runs on your system is ran via something known as a process, with that simply being the running instance of a program.

All the processes that run on your system are assigned identifiers. These can be helpful if you want to monitor the process (for example, such as to see how much memory or CPU it is using), or maybe if you want to end it if it starts to hang or just act a bit funky.

The identifiers that get attached to all these processes are known as PIDs and PPIDs.

What is a PID?

PID stands for «process ID». Again, this is simply the identifier that gets attached to a program when it starts running, and can be helpful if you need to interact with the process in one way or another.

What is a PPID?

PPID is quite closely related to a PID. PPID stands for «parent process ID», and if you didn’t get it already, it simply stands for the process that created the process you are checking.

For example, let’s say that we have two processes. One is named «spawner», and has a process ID (or PID) of 7234. Our second process, «email client», has a process ID of 7456 when we create it. Our spawner program starts our email client, resulting in our email client having a PID of 7456, and a PPID of 7234, since the spawner (which had the PID of 7234) is what spawned the email client.

Now that you have brushed up your basic, let’s see how to get the process ID in Linux.

Getting the PID of a process

The important thing here is to know the name of the process whose PID you want to find.

If you know the exact process name, you can get its process ID using the pidof command:

Easier said than done because you may not always know the exact process name. Good thing here is that pidof command works with tab completion so if you know the starting few letters of the process name, you can hit tab to get matching suggestions.

Example of pidof command which is used for finding PID of a process in Linux

However, that may not always work if the process name doesn’t match to what you think it is called. For example, the process for Edge browser on Linux is called msedge . It doesn’t start with ‘edge’ and the tab completion won’t work if you focus on ‘edge’.

So, what you can do is to resort to the ps command in Linux to list all the running processes from all users and then use grep on the output to filter the result.

ps aux | grep -i partial_process_name

There is a dedicated command that combines the features ps and grep command and it is unsurprisingly called pgrep:

pgrep partial_or_exact_process_name

pgrep command

The default output shows only the PIDs without any information on the process. This could be troublesome if there is more than one process IDs returned for your searched term.

Hence, I suggest using the listing feature to make sure that you are getting the PID of the desired process.

pgrep -l partial_or_exact_process_name

pgrep command example

You may also use the top command to get the process information but it cannot be used in scripts.

You can use the pstree command to get the PIDs of all running process on your Linux system: pstree -p -a

Getting PPID from a child process’s PID

Once you know the PID of a process, it is effortless to find the PPID for that process.

You can simply run the following command, replacing PID with the current process (child) ID:

In a shell, the above command and $ should both return the same output:

And that’s about everything there is to finding PIDs and PPIDs!

Checking the PID and PPID of the currently running process

If you’re in a shell such as Bash, it’s extremely easy to find the PID and PPID of the calling process (which will usually be the shell).

Bash stores the PID’s value under the $$ variable, and the PPID under the $ variable:

PID and PPID of current shell

And it’s that easy! Finding the PIDs and PPIDs of other processes isn’t much harder either.

Wrapping up

You should now know everything you need to find both PIDs and PPIDs for running processes on your system.

If you need any help getting something working, or just got some remaining questions, feel free to leave that and anything else in the comments below.

Источник

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.

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.

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

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

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

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.

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.

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.

Источник

What do the identifiers PID, PPID, SID, PGID, UID, EUID mean?

unix.stackexchange.com/questions/82724 has names for PGID and SID, if that’s what you’re looking for.

Two possibilities: your teacher wants you to print environment variables variables or your teacher wants you to use UNIX APIs to get the values that the system put into those variables. E.g. PPID is parent’s process PID. Try echo $PPID to see it in your environment.

1 Answer 1

  • PID — Process ID
  • PPID — Parent Process ID
  • SID — Session ID
  • PGID — Process Group ID
  • UID — User ID
  • EUID — Effective User ID

Take a look at this SO Post and the first answer for a healthy explanation of what they’re for.

3.270 Parent Process ID

An attribute of a new process identifying the parent of the process. The parent process ID of a process is the process ID of its creator, for the lifetime of the creator. After the creator’s lifetime has ended, the parent process ID is the process ID of an implementation-defined system process.

3.343 Session

A collection of process groups established for job control purposes. Each process group is a member of a session. A process is considered to be a member of the session of which its process group is a member. A newly created process joins the session of its creator. A process can alter its session membership; see setsid(). There can be multiple process groups in the same session.

3.296 Process Group

A collection of processes that permits the signaling of related processes. Each process in the system is a member of a process group that is identified by a process group ID. A newly created process joins the process group of its creator.

3.297 Process Group ID

The unique positive integer identifier representing a process group during its lifetime.

3.142 Effective User ID

An attribute of a process that is used in determining various permissions, including file access permissions; see also User ID.

† Note that the EUID and EGID (Effect Group ID) are not used for filesystem permissions under Linux which takes filesystem’s FSUID and FSGID fields respectively instead.

Источник

Читайте также:  Линукс минт темы значков
Оцените статью
Adblock
detector