LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 05-07-2009, 09:42 AM   #1
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
Problem with Signals in multiprocessor multi threaded applications


Hi.

When does an process response to a signal like SIGQUIT? I mean to say if the process is executing in the kernel space it will only respond to the signal once it comes back to user space. If it never returns from kenel space the signal cannt be processed.

If I am wrong plz correct me.

We have a scenario we have a multiprocessor system and multithreaded process running on all processors.

One of the thread in the process is in kernel mode. What will happen if a SIGQUIT is send from the second process running at the other processor.

In case another thread in the 1st process get a chance to run (which is at user space )receives the signal how will t response?

Thanks in advance
 
Old 05-07-2009, 01:37 PM   #2
titan22
LQ Newbie
 
Registered: Apr 2009
Posts: 17

Rep: Reputation: 3
Your first sentence "if it never returns from kenel space the signal cannt be processed." is correct.

Threads (in proceses 1) in user space will process the SIGQUIT handler immediately and exit. The reason they will process immediately is because for example timer interrupt happens so frequently that drives the running user threads in and out user/kernel space all the time.

The pending signal is still attached to the process(thread group to be more accurate) as long as there are still threads in this group. The thread in kernel space will eventually return to user space and process the SIGQUIT handler. The pending SIGQUIT signal is cleared when all threads in the thread group have processed the SIGQUIT handler.

Last edited by titan22; 05-07-2009 at 01:41 PM.
 
Old 05-08-2009, 12:51 AM   #3
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks Titan,

You said when all threads have processed the signal. We have a case here where one thread is not coming back from kernel space. So I do believe that the Process will have to wait for the return.

Moreover if that thread in kernel space has been placed in a wait_queue wil there be any other scenario?

Thanks again
 
Old 05-08-2009, 02:16 PM   #4
titan22
LQ Newbie
 
Registered: Apr 2009
Posts: 17

Rep: Reputation: 3
If the target thread is expecting an signal it should go to sleep by setting TASK_INTERRUPTIBLE state. Threads in TASK_UNINTERRUPTIBLE won't be woken up by signals.

The target thread in TASK_INTERRUPTIBLE state (wait_queue kernel mode) will be woken up when a SIGQUIT signal is sent by other threads. The woken thread should check if there is a pending signal and decides if it should go back to sleep (wait_queue) or bail out with EINTR. Eventually the thread is back to user mode and the signal handler will be processed.

Hundreds of examples are available if you search "TASK_UNINTERRUPTIBLE".

set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&conn->chanwait, &myself);

..... check signals when woken up ....

ret = -EINTR;
if (signal_pending(current))
goto error_unwait;
 
Old 05-11-2009, 12:29 AM   #5
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks Titan22

I found out that any active thread in the 1st application can receive the SIGQUIT and will take action for the whole process. So whether other threads are in kerner/user space won't make a difference unless we want the signal to be handled by specific thread.

Thanks again
 
  


Reply


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
apache: running multi-threaded or multi fork? Swakoo Linux - General 1 03-20-2008 07:18 AM
How to debug a multi-threaded program? nalsrayatko Programming 4 11-29-2007 01:57 PM
multi-threaded sliding window mjl3434 Programming 2 10-24-2005 04:16 PM
Signal Handling in Multi-Threaded Applications shilpig Linux - Software 1 07-15-2004 07:50 AM
Multi-Threaded C pragti Programming 1 06-01-2004 10:50 AM


All times are GMT -5. The time now is 02:50 AM.

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