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.

2

3 Answers 3

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .