Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-28-2004, 10:34 AM   #1
LQ Newbie
Registered: Jan 2004
Location: UK
Distribution: LFS
Posts: 15

Rep: Reputation: 0
Signal Handling with LinuxThrreads


I have a multi-threaded daemon which starts child processes and reads the output from them via a pipe, with a controlling thread for each child process. The daemon needs to listen for SIGCHLD to tell when the child has been stopped/continued or has exited.

The problem I'm having is that LinuxThreads doesn't send the SIGCHLD to the daemon process, but instead sends it to the thread that started the child - which is contrary to POSIX.

I can't handle the SIGCHLD asynchronously because none of the pthread functions are asnyc-signal-safe, and at the very least I'd need to lock the variable I'm accessing. So, it looks like I'll have to have two threads for each child - one to read its output via the pipe, and another to sit and wait synchronously with sigwait(). However, the docs for sigwait() say that you should only have one thread in the whole process waiting for a particular signal at any one time - but I would have as many sigwait()s as I have child processes.

It seems then that there's no safe way to proceed. Can anyone suggest another way of doing this?
Old 05-01-2004, 02:56 PM   #2
LQ Newbie
Registered: Jan 2004
Location: UK
Distribution: LFS
Posts: 15

Original Poster
Rep: Reputation: 0
I've found a solution that appears to work, so in case someone else has a similar problem, I'll add it here.

I tried doing multiple sigwait()s, but that doesn't work at all. So, I replaced the sigwait() loop with a sleep() loop and installed an async signal handler. Despite none of the pthread functions being async-signal safe, they should be okay to use anyway because the interrupted thread is always in a known state - ie., it is sleeping. I might try changing this to only use one thread per child in the future, which should be possible by using pthread_sigmask() to control when an async signal is delivered by blocking and unblocking the signals when the thread isn't holding any mutexes.

Of course both of these solutions could be prone to deadlocks if there's some locking being done by library functions that I'm not aware of, but if that's the case then I haven't seen it yet. Here's hoping.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads in signal handling shilpig Programming 3 08-20-2009 04:14 AM
Signal handling......... rajsun Programming 2 06-28-2005 09:10 AM
Signal handling from bash shy Programming 2 11-20-2004 09:41 AM
how to detect that I'm handling signal igor.kopriva Programming 2 10-01-2004 06:46 AM
Signal handling Mohsen Programming 2 07-30-2003 07:55 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration