A
Asfand Yar Qazi
Hi,
Here's some test code that demonstrates what I'm doing:
----------------------cut here----------------------
#!/usr/bin/ruby -w
trap_quit = lambda { |sig|
signame = Signal.list.find {|k, v| v == sig }[0]
STDERR.puts("Trapping signal #{signame}")
}
huphandler = inthandler = termhandler = chldhandler = nil
huphandler = trap("HUP", &trap_quit)
inthandler = trap("INT", &trap_quit)
termhandler = trap("TERM", &trap_quit)
cmd_exitstatus = nil
chldhandler = trap("CHLD") {
STDERR.puts("Trapping signal CHLD")
begin
# tmppid, status = Process.wait2(cmdpid)
tmppid = Process.wait
status = $?
cmd_exitstatus = status.exitstatus
STDERR.puts("Process::Status => " + status.inspect)
STDERR.puts("exitstatus => " + cmd_exitstatus.inspect)
if ! status.exited?
raise "ARGH! The child has not exited yet!"
end
rescue Errno::ECHILD => e
STDERR.puts("Command failed - probably ok? #{e.inspect}")
# bah, ignore it, just means a command failed
end
}
cmdpid = fork {
begin
exec("dd", "if=/dev/zero", "of=/tmp/zerofile1.asdfsdf",
"bs=1", "count=333000000")
rescue Errno::ENOENT => e
STDERR.puts e.message
exit 127
end
}
while(cmd_exitstatus.nil?)
sleep 1
STDOUT.puts "still going..."
STDOUT.flush
end
----------------------cut here----------------------
To see the problem, run the command, then press CTRL-C while it's
running. It will say "ARGH! The child has not exited yet!"
Inside the CHLD handler, exitstatus should be the valid exit status of
the child process. However, it is nil. This is really really bad,
because it seems to imply that the child signal, which is meant to be
caught when a child exits, is being called while the child has NOT exited.
Anyone tell me what I'm doing wrong?
Thanks
Here's some test code that demonstrates what I'm doing:
----------------------cut here----------------------
#!/usr/bin/ruby -w
trap_quit = lambda { |sig|
signame = Signal.list.find {|k, v| v == sig }[0]
STDERR.puts("Trapping signal #{signame}")
}
huphandler = inthandler = termhandler = chldhandler = nil
huphandler = trap("HUP", &trap_quit)
inthandler = trap("INT", &trap_quit)
termhandler = trap("TERM", &trap_quit)
cmd_exitstatus = nil
chldhandler = trap("CHLD") {
STDERR.puts("Trapping signal CHLD")
begin
# tmppid, status = Process.wait2(cmdpid)
tmppid = Process.wait
status = $?
cmd_exitstatus = status.exitstatus
STDERR.puts("Process::Status => " + status.inspect)
STDERR.puts("exitstatus => " + cmd_exitstatus.inspect)
if ! status.exited?
raise "ARGH! The child has not exited yet!"
end
rescue Errno::ECHILD => e
STDERR.puts("Command failed - probably ok? #{e.inspect}")
# bah, ignore it, just means a command failed
end
}
cmdpid = fork {
begin
exec("dd", "if=/dev/zero", "of=/tmp/zerofile1.asdfsdf",
"bs=1", "count=333000000")
rescue Errno::ENOENT => e
STDERR.puts e.message
exit 127
end
}
while(cmd_exitstatus.nil?)
sleep 1
STDOUT.puts "still going..."
STDOUT.flush
end
----------------------cut here----------------------
To see the problem, run the command, then press CTRL-C while it's
running. It will say "ARGH! The child has not exited yet!"
Inside the CHLD handler, exitstatus should be the valid exit status of
the child process. However, it is nil. This is really really bad,
because it seems to imply that the child signal, which is meant to be
caught when a child exits, is being called while the child has NOT exited.
Anyone tell me what I'm doing wrong?
Thanks