LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2015, 10:10 AM   #1
fante
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Rep: Reputation: Disabled
Help on 'signal' object.


Hi:
May someone share knowledge about 'signals'?
I have read some documentation about it but I still don't find how exactly is a 'signal' routine executed. Does this routine gets executed at 'owner' process context? At the beginning or end or in the middle of 'owner' porcess? Or at another 'process' context?
Please help.

Last edited by fante; 11-05-2015 at 10:11 AM.
 
Old 11-05-2015, 12:58 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Welcome to LQ.

Signals are a form of interprocess communications. The fact that a signal is sent comprises the total communication. In code you can set up a signal handler, and when the given signal occurs the signal handler gets called, the example link below does exactly what I'm describing. Confusion may be sometimes because a lot of handlers are automatically established. For instance if you create a child process using fork(), the parent process will receive a signal if/when the child process terminates. But in many cases, new coders may not understand that they need to look for that terminate signal from the child, or that it even is part of that programming mode, and then also not understand the method by which that signal may arrive.

Why not review the example code here and try it out on your own.
 
Old 11-05-2015, 01:02 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Signals interrupt the running process and run the signal handler in the process context. When they return the process resumes.
 
Old 11-05-2015, 03:08 PM   #4
fante
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Still confused..

Thanx for your answer. I made the mistake to use the 'owner' word instead of 'target' (process).
I have read your explanations and links, however I still have these questions:
1) So, a 'signal' handler execution is done when the 'target' process receives its execution token from the Scheduler?
2) Or a 'signal' handler execution takes place in whatever process 'context' that happens to be executing when the 'signal' was sent? (The same as a hardware ISR).

Last edited by fante; 11-06-2015 at 05:41 AM.
 
Old 11-05-2015, 06:17 PM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by fante View Post
1) So, a 'signal' execution is done when the 'target' process receives its execution token from the Scheduler?
2) Or a 'signal' execution takes place in whatever process 'context' that happens to be executing when the 'signal' was sent? (The same as a hardware ISR).
Signals are sent to specific processes, not to the process that happens to be executing when the signal is sent.

In the interactive shell, you can send signals using the kill command. It requires a process ID. In a program, you would use the kill(2) system call, which also takes a process ID as a parameter. The process with this ID will receive the signal.

Signals can also be sent to groups of processes; see the man pages for the kill(1) command and the kill(2) system call.

Signals can also be sent from the kernel without the kill system call. For example, if a process accesses protected memory, or executes a non-existing or privileged instruction, or divides by zero.

Last edited by berndbausch; 11-05-2015 at 06:19 PM.
 
Old 11-06-2015, 08:21 AM   #6
fante
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanx for your replies.
From your answers and some links provided above, in summary:

1) A signal handler is executed when the target process gets its execution token form the Scheduler. This can be at the very beginning if there are corresponding 'signal pending' bits enabled.

2) Once the target process is running, its 'signal pending' bits are evaluated whenever a system call is performed. This way the signal handler can be executed in between the execution slice of the target process.
 
  


Reply



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
glib-object get return value from a signal in the callback function joel2001k Programming 1 02-09-2009 12:57 AM
object detector (preferably infrared) that can detect an object 3 feet away schneidz Linux - Embedded & Single-board computer 5 01-21-2009 04:21 PM
Allthough squid has 1 object, it still asks object to http server markraem Linux - Server 0 10-08-2007 11:40 AM
Event driven object-to-object: C++ template class mecanism ( NOT STL or STDC++) bretzeltux Programming 2 12-23-2003 02:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:47 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration