Hi all,
On Solaris 5.11 11.3 machine.
I noticed that if i execute a bash script within a bash script, and i use & to execute the script, if i "ptree -a" the process id of the second script (one with &) - I see its parent process is init, this behavior is different from Linux.
Why is this happening ? by design ?
Does bash interpreter (or whatever) see I put & after the script and knows to attach it to Init process as parent ? (to put as background)
In my test case, aun.sh run the script bun.sh, first test is to execute command ./bun.sh and second test is execute ./bun.sh &
I created the following script ("aun.sh"):
admin@solaris113:~/drivertest$ cat aun.sh
#!/bin/bash
./bun.sh &
This is bun.sh :
root@solaris113:~/drivertest# cat bun.sh
#!/bin/bash
echo SLEEPING
sleep 60
Lets examine ps and ptree while bun is executed:
root@solaris113:~/drivertest# ./aun.sh
root@solaris113:~/drivertest# SLEEPING
root@solaris113:~/drivertest# ps -efl | grep sleep
0 S root 17653 1 0 40 20 ? 2243 ? 13:46:27 pts/3 0:00 sleep 60
0 S root 17655 17641 0 50 20 ? 2164 ? 13:46:33 pts/3 0:00 grep sleep
root@solaris113:~/drivertest# ptree -a 17653
1 /usr/sbin/init
17653 sleep 60
root@solaris113:~/drivertest#
and if i remove the & ampersand from aun.sh:
root@solaris113:~/drivertest# cat aun.sh
#!/bin/bash
./bun.sh
I get this:
root@solaris113:~/drivertest# ./aun.sh
SLEEPING
^Z
[1]+ Stopped ./aun.sh
root@solaris113:~/unix/QA/drivertest# ps -efl | grep sleep
0 T root 17677 17676 0 40 20 ? 2243 13:50:25 pts/3 0:00 sleep 60
0 S root 17679 17641 0 50 20 ? 2164 ? 13:50:34 pts/3 0:00 grep sleep
root@solaris113:~/drivertest# ptree -a 17677
1 /usr/sbin/init
804 /usr/lib/ssh/sshd
17622 /usr/lib/ssh/sshd
17623 /usr/lib/ssh/sshd
17624 -bash
17640 su
17641 bash
17675 /bin/bash ./aun.sh
17676 /bin/bash ./bun.sh
17677 sleep 60
root@solaris113:~/drivertest#