Review your favorite Linux distribution.
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 01-03-2005, 03:14 PM   #1
LQ Newbie
Registered: Dec 2004
Location: Bucharest
Distribution: debian
Posts: 4

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

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

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
Registered: Feb 2004
Posts: 47

Rep: Reputation: 15

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.

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

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
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
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
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.


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
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 > Forums > Non-*NIX Forums > Programming

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