Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.