Operating System - HP-UX
1752680 Members
5576 Online
108789 Solutions
New Discussion юеВ

Re: HPUX 11.23i - process grouping and subshells

 
Rob Lindsay
Occasional Advisor

HPUX 11.23i - process grouping and subshells

I have a question regarding the scenario below. When grouping the sleep and the echo and putting them both in the background it produces what looks like 6 child copies of the current script running the sleeps as children. Note that if you do not group the commands and just run the sleep in the background you do not get the 6 copies and the sleeps run as children of the original script (i.e. PID 26076).

My question is, are these actually 6 running copies of the script or are they just subshells given the name of the current script.

Script that was run:
#!/bin/sh
x=1
while [ ${x} -le 6 ]
do
( nohup sleep 10; echo ${x} ) &
x=$(expr ${x} + 1)
done
sleep 10

Processes list while the script was running:

systest 26090 26089 0 16:31:12 pts/19 0:00 sleep 10
systest 26086 26076 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
root 8777 933 0 11:11:50 ? 0:00 sshd: systest [priv]
systest 8909 8907 0 11:11:57 pts/19 0:00 -ksh
systest 26082 26080 0 16:31:12 pts/19 0:00 sleep 10
systest 22879 22816 0 10:43:10 ? 0:00 sshd: systest@pts/14
systest 26078 26077 0 16:31:12 pts/19 0:00 sleep 10
systest 26095 26076 0 16:31:12 pts/19 0:00 sleep 10
systest 26080 26076 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
systest 26077 26076 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
systest 26092 26076 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
systest 22881 22879 0 10:43:10 pts/14 0:00 -ksh
systest 26076 8909 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
systest 26089 26076 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
systest 26088 26086 0 16:31:12 pts/19 0:00 sleep 10
systest 8907 8777 0 11:11:56 ? 0:01 sshd: systest@pts/19
systest 26104 22881 0 16:31:17 pts/14 0:00 grep systest
systest 26083 26076 0 16:31:12 pts/19 0:00 /bin/sh /app/systest/runs/foo2.sh
systest 26094 26092 0 16:31:12 pts/19 0:00 sleep 10
systest 26103 22881 5 16:31:17 pts/14 0:00 ps -ef
systest 26085 26083 0 16:31:12 pts/19 0:00 sleep 10
root 22816 933 0 10:43:06 ? 0:00 sshd: systest [priv]
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: HPUX 11.23i - process grouping and subshells

Hi:

While these are subshells (children) insofar as they can't alter their parent's variables, they do inherit all of their parent's environment when initiated. In that sense they are copies of the parent (as in 'fork' and 'exec').

Regards!

...JRF...
Rob Lindsay
Occasional Advisor

Re: HPUX 11.23i - process grouping and subshells

Thanks JR,

Further to my question, as far as I can see the six child processes of the original script (PID 26076) cannot actually be running copies of that script even though the COMMAND listed in ps is the same name. If they were running copies then 6 more sleeps would be forked and the script would never end ...
Dennis Handly
Acclaimed Contributor

Re: HPUX 11.23i - process grouping and subshells

>Processes list while the script was running:

Please use the following to provide a nice indented list:
$ UNIX95=1 ps -H -fu systest

You'll also need to attach it so it doesn't get reformatted.

>are these actually 6 running copies of the script or are they just subshells given the name of the current script.

The latter. These are subshells executing a pipeline.

>cannot actually be running copies of that script even though the COMMAND listed in ps is the same name.

Right. They are only executing parts of the original script but since they were forked, everything in ps(1) looks the same.

>JRF: In that sense they are copies of the parent (as in 'fork' and 'exec').

You mean as in just "fork" and nothing else.
Rob Lindsay
Occasional Advisor

Re: HPUX 11.23i - process grouping and subshells

Dennis, Thanks for the formatted ps output suggestion this displays heirachy well!

A formatted and order ps list is now attached.
Dennis Handly
Acclaimed Contributor

Re: HPUX 11.23i - process grouping and subshells

>displays hierarchy well!

This shows the 6 subshells, each with a sleep child. And a sleep in the original shell.
Rob Lindsay
Occasional Advisor

Re: HPUX 11.23i - process grouping and subshells

Yes. It is clear now what is happening.

It is a shame ps displays these subshells with same name as their parent though, quite confusing until you find out what's going on.

Thanks for your help !
Rob Lindsay
Occasional Advisor

Re: HPUX 11.23i - process grouping and subshells

Explaination above.