2009-12-10 23:29:25     Linuxthreads and sigaction

Document created by Aaronwu Employee on Aug 20, 2013
Version 1Show Document
  • View in full screen mode

2009-12-10 23:29:25     Linuxthreads and sigaction

Srinivas Nagathihalli (INDIA)

Message: 83373   

 

Hi,

 

  I am implementing a multithreaded program and it's organization is like the following. The main thread spwans two threads and the two spawned threads spwan a child process each using vfork and exec. I need to monitor whether the child process has exited or not by catching the SIGCHLD signal in the threads.

 

The pthreads man page says

 

"LinuxThreads does not support the notion of process-directed signals: signals may only be sent to specific threads"

 

Is it correct to expect that each thread needs to install it's own signal handler to handle SIGCHLD signal?

 

But when I tried the behaviour is different. The signal handler installed last (by one of the two threads) always seems to get called whichever child process is killed.

 

Also I tried creating a seperate thread to handle signals, by blocking all signals in the main thread and unblock signals to catch in this waiting thread. But that also doesn't work.

 

(please also see my post here   blackfin.uclinux.org/gf/project/uclinux-dist/forum/?action=ForumBrowse&forum_id=39&thread_id=37394&_forum_action=ForumMessageBrowse

 

Srinivas.

QuoteReplyEditDelete

 

 

2009-12-11 10:49:50     Re: Linuxthreads and sigaction

Robin Getz (UNITED STATES)

Message: 83402   

 

Srinivas:

 

Just to double check - what release are you using?

 

-Robin

QuoteReplyEditDelete

 

 

2009-12-12 01:47:41     Re: Linuxthreads and sigaction

Srinivas Nagathihalli (INDIA)

Message: 83406   

 

Hi,

 

I am using uclibc-dist version 9169, kenel version 7868 and toolchain version 3740.

 

Srinivas.

QuoteReplyEditDelete

 

 

2009-12-29 01:33:03     Re: Linuxthreads and sigaction

Srinivas Nagathihalli (INDIA)

Message: 84020   

 

Hi,

 

  Can anybody throw some light on this?

 

Srinivas.

QuoteReplyEditDelete

 

 

2009-12-29 03:03:22     Re: Linuxthreads and sigaction

Mike Frysinger (UNITED STATES)

Message: 84023   

 

considering threads all share the same memory/state, and a signal handler has a dedicated stack, why do you care that each thread handles its own SIGCHLD signal ?

 

at any rate, you should review the documentation:

  pauillac.inria.fr/~xleroy/linuxthreads/faq.html#J

QuoteReplyEditDelete

 

 

2009-12-29 05:29:48     Re: Linuxthreads and sigaction

Srinivas Nagathihalli (INDIA)

Message: 84051   

 

Two reasons.

 

1. I cannot use global variables, my application framework makes it very difficult, and each thread that spawns the child process has to do something very "child specific".

 

2. I want to be sure of the behaviour.

 

 

 

I tried using sigwait (after reading the documentation)

 

I blocked SIGCHLD signal in the initial thread, then spawned two threads which in turn spawn one child process each.

 

I called sigwait (in the main thread) adding only SIGCHLD to the signal set, but sigwait does not return when any of the child process it killed.

 

However when I call sigpending in the spawned threads, I do see SIGCHLD pending in the queue!

 

 

 

Next I tried by spawning a (dedicated )thread just to install a signal handler to catch SIGCHLD and this seems to work.Whenever any of the child process is killed the signal handler gets called. I am left with no option but to use this method.

 

Anyway, thanks for your pointer.

 

Srinivas.

QuoteReplyEditDelete

 

 

2009-12-29 11:28:19     Re: Linuxthreads and sigaction

Mike Frysinger (UNITED STATES)

Message: 84053   

 

global variables is irrelevant.  there is no TLS support in linuxthreads, so the only way to pass state is via global variables.

 

if you record the different pids in an array, you can easily figure out which child you're handling if you use sigaction as the pid is passed to the signal handler.

QuoteReplyEditDelete

 

 

2009-12-29 23:51:04     Re: Linuxthreads and sigaction

Srinivas Nagathihalli (INDIA)

Message: 84056   

 

Your first sentence is kind of confusing to me. You say global variables are irrelevant and also say using them is the only way.

 

Anyway, thanks a lot for answering my questions Mike.

 

Srinivas.

QuoteReplyEditDelete

 

 

2009-12-29 23:58:49     Re: Linuxthreads and sigaction

Mike Frysinger (UNITED STATES)

Message: 84057   

 

i meant your position on avoiding global variables.  you cant avoid them with linuxthreads.

QuoteReplyEditDelete

 

 

2009-12-30 00:30:21     Re: Linuxthreads and sigaction

Srinivas Nagathihalli (INDIA)

Message: 84058   

 

Ok.

 

But if I could use  sigwait I could have avoided that.  Whenever I return from sigwait I can send messages to other threads using pipe.

 

Srinivas.

Attachments

    Outcomes