Quote:
Originally Posted by nikunjbadjatya
I tried running it as
Code:
[Terminal 1]
#./1.sh
...
...
[Terminal 2]
#./script_tree.sh 1.sh
1.sh: No such process.
No parent processes.
|
I cannot reproduce that on my machine (Ubuntu 10.10) using bash, dash or sh. Obviously, the script cannot find any running processes with 1.sh as the command, i.e.
ps -C 1.sh returns no processes.
Also, if
Code:
ps x -o pid,args | grep -e 1.sh
returns no matches, then 1.sh has already exited and reaped.
If a process is no longer seen by ps, it is impossible to find which processes it started. (You can, however, use the Linux audit service to track program executions (exec system calls) and process creation (fork system calls), and afterwards look at the log to find out which processes spawned which.
My script only takes a snapshot of the current process relationships.
Quote:
Originally Posted by nikunjbadjatya
I checked with below command and found nothing.
Code:
#ps -ef | grep 1.sh
|
Then 1.sh is no longer running, I'd say.
I tried with these four scripts, 1.sh to 4.sh:
Code:
#!/bin/sh
echo "1.sh ($$): Start"
./2.sh &
sleep 1
./3.sh &
sleep 1
./4.sh &
sleep 1
wait
echo "1.sh ($$): Exit"
Code:
#!/bin/sh
echo "2.sh ($$): Start"
./3.sh &
sleep 1
./4.sh &
sleep 1
wait
echo "2.sh ($$): Exit"
Code:
#!/bin/sh
echo "3.sh ($$): Start"
./4.sh &
sleep 1
wait
echo "3.sh ($$): Exit"
Code:
#!/bin/sh
echo "4.sh ($$): Start"
sleep 1
echo "4.sh ($$): Exit"
I started the above
./1.sh in one terminal, and in about a second, ran
./script_tree.sh 1.sh in another terminal. This is the result I get:
Code:
/bin/bash ./1.sh
/bin/bash ./2.sh
/bin/bash ./4.sh
sleep 1
sleep 1
/bin/bash ./3.sh
/bin/bash ./4.sh
sleep 1
sleep 1
sleep 1
If you wait for too long, 1.sh exits, and you'll get the "1.sh: No such process.", "No parent processes." error message.