Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting SIGCHLD when a child process dies #3283

Closed
jensnockert opened this Issue Aug 25, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@jensnockert
Copy link

commented Aug 25, 2015

You do not get a signal when a child process dies, you should get SIGCHLD.

Example, the following code works on MRI (and is differently broken on pre-9k JRuby, where you do get SIGCHLD, but the processed is reaped by Java)

https://gist.github.com/jensnockert/05e03714f57ee04ec2da

@jensnockert

This comment has been minimized.

Copy link
Author

commented Aug 25, 2015

Okay, running dtrace on this

dtrace -qn '
proc:::signal-discard
{
        printf("Process %d discarded signal %d\n",
        args[1]->pr_pid,args[2]);
}'

I get Process 26312 discarded signal 20 so we're discarding the SIGCHLD.

@jensnockert

This comment has been minimized.

Copy link
Author

commented Aug 25, 2015

@headius helped me find that if you add java.lang.UNIXProcess to the top of the script, it starts working. That class should probably be loaded early.

@headius

This comment has been minimized.

Copy link
Member

commented Aug 25, 2015

Root problem was that java.lang.UNIXProcess initializes after the user's trap is installed, and it then proceeds to reset SIGCHLD handling to default. According to sigaction man page, default behavior for SIGCHLD is to discard, so we silently lose the trap and the signal.

I have a fix that forces java.lang.Process and java.lang.UNIXProcess to load before setting up the Signal module. That should guarantee the JVM's SIGCHLD handler has been installed and that it will be overwritten by the user's trap.

@headius headius closed this in 627d84c Aug 25, 2015

@headius headius added this to the JRuby 9.0.1.0 milestone Aug 25, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.