LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-20-2010, 11:25 AM   #1
feiyinzilgd
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Rep: Reputation: 0
Question do threads in the process share the signal handler?


Hi
I am studying the Advanced Programming in the Unix Environment these days. When I come to the chapter of Threads and signals, I find it difficult for me to understand the statement that the signal disposition is shared by all threads in the process.

Dose it mean that threads in the same process share the signal handler or just the attributes that set by sigaction ?



I will appreciate your helping me.
 
Old 08-21-2010, 08:10 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,264

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
It's true that signals are sent to the (overall) process (pid); you can't send a signal to an individual thrd, so you need to be real careful and ideally minimize the amt of code in a sig handler routine.
Best to just set a flag for the normal code to deal with and leave it at that.
One exception I've used is to use SIGHUP to re-read the cfg file. Apache does the same.

Also, you might want to ask the mods to move this to the Programming forum (use the Report button)
 
Old 08-22-2010, 07:57 AM   #3
feiyinzilgd
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
It's true that signals are sent to the (overall) process (pid); you can't send a signal to an individual thrd, so you need to be real careful and ideally minimize the amt of code in a sig handler routine.
Best to just set a flag for the normal code to deal with and leave it at that.
One exception I've used is to use SIGHUP to re-read the cfg file. Apache does the same.

Also, you might want to ask the mods to move this to the Programming forum (use the Report button)
Thank for you reply.

From my understanding, If a nonblocking signal is sent to a process,every thread in the processs will do the same thing.Because the threads share the the signal handler.

Is that right?


I new here.This my first post in this forum.I do not know how to move my post to programming.
 
Old 08-22-2010, 12:06 PM   #4
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 285

Rep: Reputation: 61
Quote:
Originally Posted by chrism01 View Post
It's true that signals are sent to the (overall) process (pid); you can't send a signal to an individual thrd
Humm. You can send a signal to an individual thread. The POSIX API is pthread_kill
 
Old 08-22-2010, 12:13 PM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Quote:
Originally Posted by feiyinzilgd View Post
Thank for you reply.

From my understanding, If a nonblocking signal is sent to a process,every thread in the processs will do the same thing.Because the threads share the the signal handler.

Is that right?


I new here.This my first post in this forum.I do not know how to move my post to programming.
The threads will do what they are told to do. The signal handler will dictate what the threads are told to do.
 
Old 08-23-2010, 04:15 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,264

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
@fmurphy: indeed, but from that same page:
Quote:
Note that pthread_kill() only causes the signal to be handled in the context of the given thread; the signal action (termination or stopping) affects the process as a whole.
What I meant to say was that a signal sent from outside the process eg

kill -SIGHUP <pid of process>

cannot be specified to target a given thread; it's delivered to the process as a whole and the actual thread that will first respond is undefined.
 
  


Reply

Tags
signal handler


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
user-define signal handler & coredump for signal 11(SIGSEGV) Alexlun Linux - Software 2 05-24-2009 06:37 AM
How to reinstall a signal handler after exec ( Strange behaviour in signal handling ) lali.p Programming 0 09-20-2008 12:11 PM
signal SIGINT handler SOMETIMES doesn't exit Peterius Programming 3 05-25-2008 11:55 PM
signal handler routine vdx Programming 7 09-24-2007 12:43 AM


All times are GMT -5. The time now is 02:52 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