Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

|   

 
‡The kill function sends a signal to a process or a group of processes.
‡The raise function sends the signal to itself.

#include<sys/types.h>
#include<signal.h>
int kill(pid_t pid, int signo);
int raise (int signo);

both returns:0 if OK, -1 on error.

There are four different conditions for the pid argument 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 the permission to send
the signal. The term µall processes¶ excludes the system process.

3.pid<0 The signal is sent to all processes whose process group id equals the
absolute value of pid and sender and for which the sender has the permission to
send the signals. It can not send the message to system process.

4. pid==-
pid==-1 POSIX.1 leaves this condition as unspecified.
‡ The superuser can send the signal to any process.

‡ For others, the basic rule is that real or effective user id of the
sender has to equal the real or effective user id of the
receiver.

‡ If the signo is 0, then it is called null signal. In this case,


normal error checking is performed by kill, but no signal is
sent.

‡ This type is often used to find the specific process type is still
exists or not.

‡ If the process does not exists, kill returns -1 and errno is set
to ESRCH.
alarm function
‡ The alarm function allows as to set the timer that will expire at
specified time in the future.

‡ when the timer expire the SIGALRM signal is generated. If we


ignore or do not catch the signal, the 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.

1. The "seconds" value is the number of clock seconds in the future


when the signal should be generated.
2. The signal is generated by the kernel.

‡ There is only one alarm clock per process. If, when we call alarm,
there is a previously registered alarm clock for the process that has
not yet expired, the number of seconds left for that alarm clock is
returned as value of this function. The previously registered alarm
clock is replaced by the new value.
pause function
‡ The pause function suspends the calling process
until the signal caught.

‡ Syntax
#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 the handler returns.
‡ In that case, pause returns -1 with errno set to
EINTR.
Signal sets
‡ we need a data type to represent multiple signals - a signal
set.
‡ POSIX.1 defines the data type    to contain a signal set
and the following five functions to manipulate the signal sets.

Syntax

  
 
       
       
          
          

All four returns: 0 if OK, -1 on error.


            
Returns:1 if true, 0 if false.
‡ The function    initializes the signal set pointed by
set so that all the signals are excluded.

‡ The function     initializes the signal set pointed by set


so that all the signals are included.

‡ All applications have to call either sigemptyset or sigfillset once


for each signalset, before using the signal set. This is to
initialize the variables to '0'.

‡ Once we have initialized the signal set, we can add or delete


specific signals in the set.

‡ The function   to add a single signal to an existing


set, and   removes a single signal from a set.

‡ To all the functions, we always pass the ? 



?  as an argument.
sigpending function
‡ This function returns the set of signals that are blocked from
delivery and currently pending for the calling process.

‡ The set of signals is returned through the set argument.

Syntax
#include <signal.h>
int sigpending(sigset_t *set);
Returns:0 if Ok, -1 on error.
abort function

‡ Abort function causes the abnormal program termination

Syntax
#include<stdlib.h>
void abort(void);

This function never returns.

‡ This function sends the SIGABRT signal to the process. A


process should not ignore this signal.

‡ The intent of letting the process catch the SIGABRT is to


allow it to perform any cleanup that it wants to do, before
the process terminates.
sleep function
This function suspend the calling process till the specified period of
time.

Syntax
#include <unistd.h>
unisigned int sleep(unsigned int seconds);
Returns:0 or number of unslept seconds.

`  
     

  
‡ The amount of wall clock time specified by the seconds has elapsed.

‡ A signal is caught by the process and the signal handler returns.

 



‡ case1: The return value is 0.


‡ case 2: When sleep return early, because of some signal being
caught. The return value is number of unslept seconds (The
requested time- the actual time slept).
Sigaction function

‡ This function allows us to examine or modify the action


associated with a particular signal.

#include<signal.h>
int sigaction (int signo,const struct sigaction *act,
struct sigaction *oact);
RETURNS: 0 IF OK, -1 ON ERROR.
‡ signo-is the signal number whose action to be
examined or modified.

‡ *act- if this pointer is non null, we are modifying the


action.

‡ *oact-if this pointer is non null, the system returns the


previous action for the signal.
struct sigaction
{
void (*sa_handler)(int); /* addr of signal handler or SIG_IGN,
or SIG_DFL */
sigset_t sa_mask; /* additional signals to block */
int sa_flags; /* signal options*/

/* alternate handler */
void (*sa_sigaction)(int, siginfo_t *, void *);
};

‡ Once we install an action for a given signal, that action


remains installed until we explicitly change it by calling
sigaction.

You might also like