Sh and Pipes

Just a note to mention that the goddamned bourne shell puts up a wierd behaviour while piping commands. If you do this:

$ command1 | command2

command1 is actually run as the child of command2. So yes, command2 receieves a SIGCHLD when command1 exits.

So anyone out there modifying the start script of an SSL enabled proxy/webserver instance, watch out. When you echo the password and pipe it to the watchdog process, like this...

echo "secpasswd" | ./$PRODUCT_BIN -r $SERVER_ROOT -d $INSTANCE_CONFIG_DIR...

...the exit of the echo command sends a SIGCHLD to the watchdog, which in turn exits with a nonzero return value. But the server processes come up fine, because it's only the parent watchdog that has exited - the child watchdog, the primordial, and the worker process all come up fine, and everything works fine.

Except that when you do the startup from the admin GUI, you see an error reported - because of the non zero return status.

bash, ksh etc acts differently - no issues here. command1 and command2 are run on sibling processes, and there is no child/parent relationship as in the case of sh.

Wierd shit.

Comments:

Its because bourne shell has no concept of process groups so all children are in the parent shell's group. Signals are propagated throughout a process group. Since bourne shell and all its children are in a single process group, all processes in the group see everyone else's signals. In a Bourne shell, just run: ps -j You should see a PGID column shown up. The parent sh and ps command will have the same PGID value. Now run a ksh or bash and run the same "ps -j". The PGID column will show up again but the values will be different this time. This isn't a bug. Its been around for a long time.

Posted by Sean O'Neill on tetor 25, 2006 at 10:24 MD PDT #

Sean is correct, although this behaviour is limited to bourne shells that are not POSIX compliant. /bin/sh on FreeBSD and /usr/xpg4/bin/sh on Solaris do not exhibit this behaviour.

Posted by Ceri Davies on tetor 25, 2006 at 11:24 MD PDT #

But /usr/xpg4/bin/sh is a hacked ksh88 (created from the same sources as /usr/bin/ksh) and not a bourne shell. "sh" just means something like system shell and may not be bourne shell itself. The good news is that the Bourne shell issue may go away if http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6486407 gets implemented (right after http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=4113420 and http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6437624)... :-)

Posted by Roland Mainz on tetor 27, 2006 at 04:19 MD PDT #

best wishes for you

Posted by 免费电影 on gusht 07, 2007 at 11:42 PD PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

user13334066

Search

Archives
« prill 2014
DieHënMarMërEnjPreSht
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today