My Command Interpreter is bash shell.After opening terminal on my OS(cent OS), I have executed following commands:
scenario 1
$sh -c "ps -l"
UID PID PPID TIME CMD
3038 2577 2504 00:00:00 bash
3038 2992 2577 00:00:00 ps
scenario 2
$sh
$ps -l
UID PID PPID TIME CMD
3038 2577 2504 00:00:00 bash
3038 3005 2577 00:00:00 sh
3038 3006 3005 00:00:00 ps
Observe PID and PPID of ps
.
In scenario 1, I am executing ps -l
command on sh
shell. So it's parent should be sh
i.e., it's PPID should be PID of sh
. But ps -l
command listing that it's parent is bash
. I am not understanding what is happening exactly. I am understanding the difference between scenario 1 and scenario 2. But when I am executing the same commands on another OS(ubuntu), I am getting same listing under ps -l
in scenario 3 and scenario 4, as below:
scenario 3
$sh
$ps -l
UID PID PPID TIME CMD
3038 2577 2504 00:00:00 bash
3038 2991 2577 00:00:00 sh
3038 2992 2991 00:00:00 ps
scenario 4
$sh
$ps -l
UID PID PPID TIME CMD
3038 2577 2504 00:00:00 bash
3038 3005 2577 00:00:00 sh
3038 3006 3005 00:00:00 ps
Here in both scenarios, I am getting PPID of ps
CMD as PID of sh
. What is happening exactly. Is my interpretation wrong?