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

doesn't seem to work with fork() #13

Closed
philippkeller opened this issue Dec 16, 2016 · 7 comments
Closed

doesn't seem to work with fork() #13

philippkeller opened this issue Dec 16, 2016 · 7 comments

Comments

@philippkeller
Copy link

philippkeller commented Dec 16, 2016

I'm trying to mix this chan module together with libc::fork() but somehow it doesn't work.
This is probably due to some difference between thread::spawn() and fork() but I just don't understand why it should not work.

Here's the example from the README adapted to fork(). Interestingly the INT signal works but the TERM not even though sdone is really moved into run

(this issue moved from here)

@philippkeller
Copy link
Author

I'm really a beginner in this concurrency topic so I can only utter wild guesses: Could it be that fork() with it's "copy on write" model actually copies the channel so the TERM signal is sent into another channel than the parent is running recv on? (this is assuming that Rusts threading does not do copy-on-write in threading)

@radupopescu
Copy link

radupopescu commented Jan 25, 2017

Hi!

I'm having this issue, too.

After a call to fork(), I do:

    let signal = chan_signal::notify(&[Signal::CHLD, Signal::INT, Signal::TERM]);
    // Wait for a signal or for work to be done.
    chan_select! {
        signal.recv() -> signal => {
            println!("Received signal: {:?}", signal)
        },
    }

in the parent process. No signal is received from the child process, but the INT signal is received (I generate it when doing Ctrl-C to exit).

I'm on macOS 10.12, rust 1.14 and 1.16.0-nightly (83c2d9523 2017-01-24), chan 0.1.18, chan-signal 0.2.0.

Cheers,
Radu

@BurntSushi
Copy link
Owner

My guess is that this has to do with the child process not inheriting the signal masks.

@radupopescu
Copy link

@BurntSushi Could be. Is Signal::INT by default in the signal mask?
One question, though. Is the signal mask used in the child process? In my example it is the parent process which waits on the CHLD signal.

@BurntSushi
Copy link
Owner

I don't know. Someone needs to go learn about pthread_sigmask and its behavior across parent/child processes, which is used in this crate. It's my understanding that no signals are masked by default, which is why this crate demands that you run chan_signal::notify at the very beginning of your program.

There isn't much code in this crate, but I don't have time to investigate this issue myself right now.

@radupopescu
Copy link

@BurntSushi Thanks for the feedback. I need this kind of functionality for a project, so if I find something, I'll post back here.

Cheers,

@BurntSushi
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants