LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 01-03-2005, 03:14 PM   #1
b2na
LQ Newbie
 
Registered: Dec 2004
Location: Bucharest
Distribution: debian
Posts: 4

Rep: Reputation: 0
!!! about signals !!!


[C/C++ application, Linux, signal, thread, process]

hello.
I have an application, one single process and multiple threads. Every thread has its run function. When a signal is send to the process, all threads are interrupted? And if the signal is handled, what happens next? I supose the signal is handled and then all the operations are... restarted... I'm not sure about that... can someone explain a little bit to me what happens to the running operations when a signal arrives and it's handled?

Thank you.
 
Old 01-04-2005, 05:24 PM   #2
michael_util
Member
 
Registered: Feb 2004
Posts: 47

Rep: Reputation: 15
Hello,

I am not a developer by any means ... but I believe this is entierly depends on how you write your application.

For example in order to use signals with bash scritps you need to have a trap setup for them. If I setup a trap for signal 10 (trap cmd_func 10) when I sent a signal 10 to the process it will run that function cmd_func. If I do not have a trap setup then nothing happens.

Michael.
 
Old 01-04-2005, 11:22 PM   #3
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 3,988

Rep: Reputation: 261Reputation: 261Reputation: 261
Read the man page for pthread_sigmask -- it has some info on this. POSIX specifies that a signal is only delivered to one thread, but there are a few quirks in the Linux implementation of this. Read that man page for all the gory details. There is a way (pthread_kill) to send signals between threads.

If a signal has handled, the program will continue to execurte where it left off once the signal handler has finished. The exceptions are if the handler terminates the program or jumps (e.g. via siglongjmp) somewhere else.
 
Old 01-05-2005, 04:15 AM   #4
b2na
LQ Newbie
 
Registered: Dec 2004
Location: Bucharest
Distribution: debian
Posts: 4

Original Poster
Rep: Reputation: 0
I see... Thanks for the clarification with siglongjmp... I had some problems with that too.... But there are signals sent to _the process_ and signals sent to thread with pthread_kill. In my application I have a signal sent to the process and in that process I have multiple threads. So, the signal sent to the process wil stop and restart then the threads, all the threads? (the signal is sent to one process and in that process I'm running multiple threads)
 
Old 02-04-2005, 12:34 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
As I understnd it, in your case (sig sent to process), the answer is to assume any thread will catch it, so make the sig handler avail/in all threads and set a global or something that the other threads can take notice of...
A lot of systems have a master thread that actually does something about the sig when it sees the global var is set.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
catching signals alaios Programming 3 11-16-2007 05:05 AM
!! about signals !!! b2na General 1 01-03-2005 04:37 PM
Signals Speek Programming 2 12-24-2004 04:58 AM
Catch signals C++ moyacuba Programming 2 03-18-2004 12:28 PM
trap signals AMMullan Programming 3 10-19-2003 04:31 PM


All times are GMT -5. The time now is 09:30 PM.

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