Find parent PID in shell script ?
Hello,
I know that I can with $$ inside shell script find out the PID of that shell script. But how can I get parent PID of the same script inside shell script. Example: I have MyScript and MyScript1. MyScript is calling MyScript1. So if I inside MyScript1 write $$ I will get PID of MyScript1, but how to get PID of MyScript inside MyScropt1. Is there a way? Thanks |
You can get Parent PID (PPID) using ps. These are the columns available with the -ef options:
Code:
[hector@troy ~]$ ps -ef | head -1 e.g. Code:
ps -ef | awk '$2 ~ /\<1148\>/ { print $3; }' |
Hi,
I assume you are using bash: You can use PPID. Code:
$ cat ms |
Even easier -- I didn't know there was a special shell variable for PPID.
|
Hi,
Yep, it's a read-only variable set by bash. See the manpage (part about shell variables) for all the gory details ;) |
Ok, good it is working also in "ksh"
|
hi, what is the difference between $$ and $! ?
thanks, |
Hi,
$$ -> Expands to the process ID of the (current) shell. $! -> Expands to the process ID of the most recently executed background command. man bash could have told you this...... |
All times are GMT -5. The time now is 11:28 PM. |