

This way, you can get the process ID of shell and subshell.Īnd it's that easy! Finding the PIDs and PPIDs of other processes isn't much harder either. In a shell, the above command and $" Commands to find the PID and PPID of the current process. You can simply run the following command, replacing PID with the current process (child) ID: ps -o ppid= -p PID Once you know the PID of a process, it is effortless to find the PPID for that process. 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 You may also use the top command to get the process information but it cannot be used in scripts. Hence, I suggest using the listing feature to make sure that you are getting the PID of the desired process. This could be troublesome if there is more than one process IDs returned for your searched term. The default output shows only the PIDs without any information on the process. 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 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. It doesn't start with 'edge' and the tab completion won't work if you focus on 'edge'.

For example, the process for Edge browser on Linux is called msedge. However, that may not always work if the process name doesn't match to what you think it is called. 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. If you know the exact process name, you can get its process ID using the pidof command: pidof exact_process_nameĮasier said than done because you may not always know the exact process name. The important thing here is to know the name of the process whose PID you want to find.
#BASH COMMAND LINE PS EF HOW TO#
Now that you have brushed up your basic, let's see how to get the process ID in Linux. 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. Our second process, "email client", has a process ID of 7456 when we create it. One is named "spawner", and has a process ID (or PID) of 7234. 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.įor example, let's say that we have two processes. 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. The identifiers that get attached to all these processes are known as PIDs and PPIDs. 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.

Linux process basicsĮverything that runs on your system is ran via something known as a process, with that simply being the running instance of a program.Īll the processes that run on your system are assigned identifiers. I'll explain these commands in detail but before that a quick recap of process, PID and PPID.

There are numerous ways to get the PID (Process ID) and PPID (Parent Process ID) of a given 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.
