bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[trapping SIGCHLD inside a shellscript]


From: J.Smith
Subject: [trapping SIGCHLD inside a shellscript]
Date: Tue, 10 Apr 2001 21:59:58 +0200

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: gcc
Compilation
CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' -DCONF_OSTYPE='linux-gnu' -
DCONF_MACHTYPE='i586-mandrake-linux-gnu' -DCONF_VENDOR='mandrake' -DSHELL -D
HAVE_CONFIG_H  -D_FILE_OFFSET_BITS=64  -I. -I/usr/include -I. -I./include -I
./lib -I/usr/include -O3 -fomit-frame-pointer -pipe -s -march=pentium -ffast
-math -fexpensive-optimizations
uname output: Linux myhome.home.net 2.2.17-21mdk #1 Thu Oct 5 13:16:08 CEST
2000 i686 unknown
Machine Type: i586-mandrake-linux-gnu

Bash Version: 2.04
Patch Level: 12
Release Status: release

Description:
It seems that trapping on SIGCHLD inside shellscripts doesnt work as
expected. Maybe the same thing goes for other signals too, but i havent
tested this. When I set a trap on SIGCHLD on the bash prompt, the trap works
as expected, but when I try the same thing in a shell script, the signal
doesnt seem to get caught. Let me clarify this by giving an example here.

When I do this at the prompt:

# trap "echo Signal SIGCHLD caught" CHLD
# ls -alR / >/dev/null 2>&1 &
# kill -STOP PID-of-the-ls-command

The signal gets caught as expected, and the "echo Signal SIGCHLD caught"
executes. But when I try a similar thing in a script like this:

#!/bin/sh

trap "echo Signal SIGCHLD caught" CHLD

ls -alR / >/dev/null 2>&1 &

while true
do
 sleep 3
done

And execute a "kill -STOP PID-of-the-ls-command" from another terminal, the
"Signal SIGCHLD caught" does not appear on the screen. Now I think about it,
Im not sure if the signal really doesnt get caught, or whether the echo
doesnt behave correctly here...

When I use ksh instead of bash on the same system, both the script and the
commandline version work 'correctly', and the "Signal SIGCHLD caught" echo's
on the screen.


Repeat-By:

Create the following script.

#!/bin/sh

trap "echo Signal SIGCHLD caught" CHLD

ls -alR / >/dev/null 2>&1 &

while true
do
 sleep 3
done

Execute it on the commandline
# ./script.sh

Send a kill -STOP from another terminal session:

# kill -STOP PID-of-the-ls-command




reply via email to

[Prev in Thread] Current Thread [Next in Thread]