1

back to this How do I find the PID of the last open file in terminal?

I want to know the PPID (parent id of the process) of the last executed process.

Maythux
  • 84,289
  • Sorry, but isn't that just the Terminal's inner bash instance PID, i.e. e.g. echo $$? – kos Apr 20 '15 at 16:16
  • 1
    http://askubuntu.com/questions/153976/how-do-i-get-the-parent-process-id-of-a-given-child-process?rq=1 – muru Apr 20 '15 at 16:23

3 Answers3

2

In the same terminal, run the following command:

ps -p $! -o ppid=
2

This question is ambiguous: are you asking for how to get the PPID of the last process executed in a Terminal or are you asking for how to get the PPID of the last process executed doing so via the Terminal?

If the first one, either I'm missing something or the PPID of the last process executed in the current Terminal's current inner bash instance is the current Terminal's current inner bash instance PID, which is always stored in $:

echo $$

If the second one you can run:

ps -e --sort -start_time -o ppid | head -5 | tail -1
kos
  • 35,891
0

In a terminal run this command:

<your_command> &
awk '{print $4}' "/proc/$\!/stat"

e.g.

$ gedit &                            
[1] 12130
$ awk '{print $4}' "/proc/$\!/stat"
11099
$ ps xa | grep 11099
11099 pts/0    Ss     0:01 /usr/bin/zsh
A.B.
  • 90,397