SlideShare a Scribd company logo
 Signal Concept :-
First, every signal has a name. These names all begin with the three characters SIG. For
example, SIGABRT is the abort signal that is generated when a process calls the abort function.
SIGALRM is the alarm signal that is generated when the timer set by the alarm function goes off.
Version 7 had 15 different signals; SVR4 and 4.4BSD both had 31 different signals. FreeBSD 8.0
supports 32 different signals. Mac OS X 10.6.8 and Linux 3.2.0 each support 31 different signals,
whereas Solaris 10 supports 40 different signals.
No signal has a signal number of 0. The kill function uses the signal number of 0 for a special
case. POSIX calls this value the null signal.
Numerous conditions can generate a signal:
• The terminal-generated signals occur when users press certain terminal keys. Pressing
the DELETE key on the terminal (or Control-C on many systems) normally causes the
interrupt signal (SIGINT) to be generated.
• Hardware exceptions generate signals: divide by 0, invalid memory reference, and the
like. These conditions are usually detected by the hardware, and the kernel is notified.
The kernel then generates the appropriate signal for the process that was running at
the time the condition occurred.
• The kill(2) function allows a process to send any signal to another process or process
group. Only if we must be the owner of the process that we’re sending the signal to,
or we must be the superuser.
• The kill(1) command allows us to send signals to other processes. This command is
often used to terminate a runaway background process.
• Software conditions can generate signals when a process should be notified of various
events. These aren’t hardware-generated conditions but software conditions.
Examples are SIGURG (generated when out-of-band data arrives over a network
connection), SIGPIPE (generated when a process writes to a pipe that has no reader),
and SIGALRM (generated when an alarm clock set by the process expires).
We can tell the kernel to do one of three things when a signal occurs. We call this the
disposition of the signal, or the action associated with a signal.
1. Ignore the signal. This works for most signals, but two signals can never be ignored:
SIGKILL and SIGSTOP. The reason these two signals can’t be ignored is to provide
the kernel and the superuser with a surefire way of either killing or stopping any
process. Also, if we ignore some of the signals that are generated by a hardware
exception (such as illegal memory reference or divide by 0), the behavior of the
process is undefined.
2. Catch the signal. To do this, we tell the kernel to call a function of ours whenever the
signal occurs. In our function, we can do whatever we want to handle the condition.
3. Let the default action apply. Every signal has a default action.
 signal Function :-
void (*signal(int signo, void (*func)(int)))(int);
Returns: previous disposition of signal if OK, SIG_ERR on error
The signo argument is just the name of the signal from 31 signal. The value of func is
(a) the constant SIG_IGN, (b) the constant SIG_DFL, or (c) the address of a function to be
called when the signal occurs. If we specify SIG_IGN, we are telling the system to ignore the
signal. (Remember that we cannot ignore the two signals SIGKILL and SIGSTOP.) When we
specify SIG_DFL, we are setting the action associated with the signal to its default value.
When we specify the address of a function to be called when the signal occurs, we are
arranging to ‘‘catch’’ the signal. We call the function either the signal handler or the signal-
catching function.
 kill and raise Functions :-
The kill function sends a signal to a process or a group of processes. The raise function allows
a process to send a signal to itself.
#include <signal.h>
int kill(pid_t pid, int signo);
int raise(int signo);
Both return: 0 if OK, −1 on error
The call raise(signo); is equivalent to the call kill(getpid(), signo);
There are four different conditions for the pid argument to kill.
1. pid >0 The signal is sent to the process whose process ID is pid.
2. pid ==0 The signal is sent to all processes whose process group ID equals the process
group ID of the sender and for which the sender has permission to send the signal.
3. pid <0 The signal is sent to all processes whose process group ID equals the absolute
value of pid and for which the sender has permission to send the signal.
4. pid == −1 The signal is sent to all processes on the system for which the sender has
permission to send the signal.
 alarm and pause Functions :-
The alarm function allows us to set a timer that will expire at a specified time in the
future. When the timer expires, the SIGALRM signal is generated. If we ignore or don’t catch
this signal, its default action is to terminate the process.
#include <unistd.h>
unsigned int alarm(unsigned int seconds);
Returns: 0 or number of seconds until previously set alarm
The second's value is the number of clock seconds in the future when the signal should
be generated. When that time occurs, the signal is generated by the kernel, although additional
time could elapse before the process gets control to handle the signal, because of processor
scheduling delays.
There is only one of these alarm clocks per process. If, when we call alarm, a
previously registered alarm clock for the process has not yet expired, the number of seconds
left for that alarm clock is returned as the value of this function. That previously registered
alarm clock is replaced by the new value. If a previously registered alarm clock for the process
has not yet expired and if the seconds value is 0, the previous alarm clock is canceled. The
number of seconds left for that previous alarm clock is still returned as the value of the
function.
The pause function suspends the calling process until a signal is caught
#include <unistd.h>
int pause(void);
Returns: −1 with errno set to EINTR
The only time pause returns is if a signal handler is executed and that handler returns.
 abort Function :-
We mentioned earlier that the abort function causes abnormal program termination
#include <stdlib.h>
void abort(void);
This function never returns
This function sends the SIGABRT signal to the caller.
 Sleep Function:-
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
Returns: 0 or number of unslept seconds
This function causes the calling process to be suspended until either
1. The amount of wall clock time specified by seconds has elapsed.
2. A signal is caught by the process and the signal handler returns.

More Related Content

PPTX
Unixppt (1) (1).pptx
PDF
Signal Handling in Linux
PDF
Usp notes unit6-8
PDF
System Programming Assignment Help- Signals
PPT
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
PPTX
07 Systems Software Programming-IPC-Signals.pptx
PPT
Traffic Signal Synchronization Operating Systems
PDF
Unix presentation.pdf
Unixppt (1) (1).pptx
Signal Handling in Linux
Usp notes unit6-8
System Programming Assignment Help- Signals
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
07 Systems Software Programming-IPC-Signals.pptx
Traffic Signal Synchronization Operating Systems
Unix presentation.pdf

Similar to AOS Chapter 6 for internal.docx (20)

PDF
Course 102: Lecture 19: Using Signals
PDF
PPTX
Unix signals
PDF
Timers in Unix/Linux
PPTX
Interrupts
PPTX
Process management
PPT
signals & message queues overview
PPTX
Arduino course
PDF
arduinocourse-180308074529 (1).pdf
DOCX
Arduino 101
PPTX
PDF
Bitcoin hardware wallets security
DOCX
Write a program called signal.c that performs the functions of t.docx
PPTX
Unit 3 timer and counter and there application .pptx
PPTX
2.4_Design_of_CPU_&_Types_of_Control_Unit[1].pptx
PPTX
asmaa hosni
DOCX
Inter Process Comunication
PPTX
Computer networks unit III CHAPTER of frameworks
PPT
Best-embedded-corporate-training-in-mumbai
PDF
Automatic Door Opener using PIR Sensor
Course 102: Lecture 19: Using Signals
Unix signals
Timers in Unix/Linux
Interrupts
Process management
signals & message queues overview
Arduino course
arduinocourse-180308074529 (1).pdf
Arduino 101
Bitcoin hardware wallets security
Write a program called signal.c that performs the functions of t.docx
Unit 3 timer and counter and there application .pptx
2.4_Design_of_CPU_&_Types_of_Control_Unit[1].pptx
asmaa hosni
Inter Process Comunication
Computer networks unit III CHAPTER of frameworks
Best-embedded-corporate-training-in-mumbai
Automatic Door Opener using PIR Sensor
Ad

Recently uploaded (20)

PPT
Presentation of a Romanian Institutee 2.
PDF
Packaging materials of fruits and vegetables
PDF
Is Earendel a Star Cluster?: Metal-poor Globular Cluster Progenitors at z ∼ 6
PPT
Animal tissues, epithelial, muscle, connective, nervous tissue
PDF
CHAPTER 2 The Chemical Basis of Life Lecture Outline.pdf
PDF
Wound infection.pdfWound infection.pdf123
PDF
BET Eukaryotic signal Transduction BET Eukaryotic signal Transduction.pdf
PPT
1. INTRODUCTION TO EPIDEMIOLOGY.pptx for community medicine
PPTX
gene cloning powerpoint for general biology 2
PDF
Worlds Next Door: A Candidate Giant Planet Imaged in the Habitable Zone of ↵ ...
PPT
LEC Synthetic Biology and its application.ppt
PDF
Unit 5 Preparations, Reactions, Properties and Isomersim of Organic Compounds...
PPTX
perinatal infections 2-171220190027.pptx
PPT
veterinary parasitology ````````````.ppt
PPTX
ap-psych-ch-1-introduction-to-psychology-presentation.pptx
PPTX
Presentation1 INTRODUCTION TO ENZYMES.pptx
PPT
Enhancing Laboratory Quality Through ISO 15189 Compliance
PPTX
PMR- PPT.pptx for students and doctors tt
PPTX
Understanding the Circulatory System……..
PPTX
A powerpoint on colorectal cancer with brief background
Presentation of a Romanian Institutee 2.
Packaging materials of fruits and vegetables
Is Earendel a Star Cluster?: Metal-poor Globular Cluster Progenitors at z ∼ 6
Animal tissues, epithelial, muscle, connective, nervous tissue
CHAPTER 2 The Chemical Basis of Life Lecture Outline.pdf
Wound infection.pdfWound infection.pdf123
BET Eukaryotic signal Transduction BET Eukaryotic signal Transduction.pdf
1. INTRODUCTION TO EPIDEMIOLOGY.pptx for community medicine
gene cloning powerpoint for general biology 2
Worlds Next Door: A Candidate Giant Planet Imaged in the Habitable Zone of ↵ ...
LEC Synthetic Biology and its application.ppt
Unit 5 Preparations, Reactions, Properties and Isomersim of Organic Compounds...
perinatal infections 2-171220190027.pptx
veterinary parasitology ````````````.ppt
ap-psych-ch-1-introduction-to-psychology-presentation.pptx
Presentation1 INTRODUCTION TO ENZYMES.pptx
Enhancing Laboratory Quality Through ISO 15189 Compliance
PMR- PPT.pptx for students and doctors tt
Understanding the Circulatory System……..
A powerpoint on colorectal cancer with brief background
Ad

AOS Chapter 6 for internal.docx

  • 1.  Signal Concept :- First, every signal has a name. These names all begin with the three characters SIG. For example, SIGABRT is the abort signal that is generated when a process calls the abort function. SIGALRM is the alarm signal that is generated when the timer set by the alarm function goes off. Version 7 had 15 different signals; SVR4 and 4.4BSD both had 31 different signals. FreeBSD 8.0 supports 32 different signals. Mac OS X 10.6.8 and Linux 3.2.0 each support 31 different signals, whereas Solaris 10 supports 40 different signals. No signal has a signal number of 0. The kill function uses the signal number of 0 for a special case. POSIX calls this value the null signal. Numerous conditions can generate a signal: • The terminal-generated signals occur when users press certain terminal keys. Pressing the DELETE key on the terminal (or Control-C on many systems) normally causes the interrupt signal (SIGINT) to be generated. • Hardware exceptions generate signals: divide by 0, invalid memory reference, and the like. These conditions are usually detected by the hardware, and the kernel is notified. The kernel then generates the appropriate signal for the process that was running at the time the condition occurred. • The kill(2) function allows a process to send any signal to another process or process group. Only if we must be the owner of the process that we’re sending the signal to, or we must be the superuser. • The kill(1) command allows us to send signals to other processes. This command is often used to terminate a runaway background process. • Software conditions can generate signals when a process should be notified of various events. These aren’t hardware-generated conditions but software conditions. Examples are SIGURG (generated when out-of-band data arrives over a network connection), SIGPIPE (generated when a process writes to a pipe that has no reader), and SIGALRM (generated when an alarm clock set by the process expires). We can tell the kernel to do one of three things when a signal occurs. We call this the disposition of the signal, or the action associated with a signal. 1. Ignore the signal. This works for most signals, but two signals can never be ignored: SIGKILL and SIGSTOP. The reason these two signals can’t be ignored is to provide the kernel and the superuser with a surefire way of either killing or stopping any process. Also, if we ignore some of the signals that are generated by a hardware exception (such as illegal memory reference or divide by 0), the behavior of the process is undefined.
  • 2. 2. Catch the signal. To do this, we tell the kernel to call a function of ours whenever the signal occurs. In our function, we can do whatever we want to handle the condition. 3. Let the default action apply. Every signal has a default action.  signal Function :- void (*signal(int signo, void (*func)(int)))(int); Returns: previous disposition of signal if OK, SIG_ERR on error The signo argument is just the name of the signal from 31 signal. The value of func is (a) the constant SIG_IGN, (b) the constant SIG_DFL, or (c) the address of a function to be called when the signal occurs. If we specify SIG_IGN, we are telling the system to ignore the signal. (Remember that we cannot ignore the two signals SIGKILL and SIGSTOP.) When we specify SIG_DFL, we are setting the action associated with the signal to its default value. When we specify the address of a function to be called when the signal occurs, we are arranging to ‘‘catch’’ the signal. We call the function either the signal handler or the signal- catching function.  kill and raise Functions :- The kill function sends a signal to a process or a group of processes. The raise function allows a process to send a signal to itself. #include <signal.h> int kill(pid_t pid, int signo); int raise(int signo); Both return: 0 if OK, −1 on error The call raise(signo); is equivalent to the call kill(getpid(), signo); There are four different conditions for the pid argument to kill. 1. pid >0 The signal is sent to the process whose process ID is pid. 2. pid ==0 The signal is sent to all processes whose process group ID equals the process group ID of the sender and for which the sender has permission to send the signal. 3. pid <0 The signal is sent to all processes whose process group ID equals the absolute value of pid and for which the sender has permission to send the signal. 4. pid == −1 The signal is sent to all processes on the system for which the sender has permission to send the signal.  alarm and pause Functions :- The alarm function allows us to set a timer that will expire at a specified time in the future. When the timer expires, the SIGALRM signal is generated. If we ignore or don’t catch this signal, its default action is to terminate the process.
  • 3. #include <unistd.h> unsigned int alarm(unsigned int seconds); Returns: 0 or number of seconds until previously set alarm The second's value is the number of clock seconds in the future when the signal should be generated. When that time occurs, the signal is generated by the kernel, although additional time could elapse before the process gets control to handle the signal, because of processor scheduling delays. There is only one of these alarm clocks per process. If, when we call alarm, a previously registered alarm clock for the process has not yet expired, the number of seconds left for that alarm clock is returned as the value of this function. That previously registered alarm clock is replaced by the new value. If a previously registered alarm clock for the process has not yet expired and if the seconds value is 0, the previous alarm clock is canceled. The number of seconds left for that previous alarm clock is still returned as the value of the function. The pause function suspends the calling process until a signal is caught #include <unistd.h> int pause(void); Returns: −1 with errno set to EINTR The only time pause returns is if a signal handler is executed and that handler returns.  abort Function :- We mentioned earlier that the abort function causes abnormal program termination #include <stdlib.h> void abort(void); This function never returns This function sends the SIGABRT signal to the caller.  Sleep Function:- #include <unistd.h> unsigned int sleep(unsigned int seconds); Returns: 0 or number of unslept seconds This function causes the calling process to be suspended until either 1. The amount of wall clock time specified by seconds has elapsed. 2. A signal is caught by the process and the signal handler returns.