Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

SIGACTION

By
Prithiviraj.M

SIGACTION
The sigaction function can be used to set a
signal disposition in a more controlled way
at the cost of complexity

Function Format
int sigaction ( int signum, const struct
sigaction *act, struct sigaction *oldact)

Description
The first argument, signum, is a
specified signal; the second
argument, sigaction, is used to set
the new action of the signal signum;
and the third argument is used to
store the previous action, usually
NULL

STRUCTURE
SIGACTION

struct sigaction
{
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *,
void*);
sigset_t sa_mask; int sa_flags;
}

FACTORS
In most cases, this consists simply of
recording the fact that a signal
occurred.
The main program then checks
periodically whether a signal has
occurred and reacts accordingly.

SIGACTION
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
sig_atomic_t sigusr1_count = 0;
void handler (int signal_number)
{
++sigusr1_count;
}

int main ()
{
struct sigaction sa;
sa.sa_handler = &handler;
sigaction (SIGINT, &sa, NULL);
printf (SIGUSR1 was raised %d times\n,
sigusr1_count);
return 0;
}

Process Termination
A process may also terminate abnormally, in
response to a signal. For instance, the SIGBUS,
SIGSEGV, and SIGFPE signals mentioned
previously cause the process to terminate.

The most powerful termination signal is SIGKILL,


which ends a process immediately and cannot
be blocked or handled by a program.Include the
<sys/types.h> and <signal.h> headers if you
use the kill function.

EXAMPLE OF EXIT CODE


%ls /
bin coda etc lib misc nfs proc sbin usr
boot dev home lost+found mnt opt root
tmp var
%echo $?
0

Waiting for Process


Termination
When a parent forks a child,the two
process can take any turn to finish
themselves and in some cases the
parent may die before the child .
In some situations, though, it is
desirable for the parent process to
wait until one or more child processes
have completed.

This can be done with the wait family


of system calls.
These functions allow you to wait for
a process to finish executing, and
enable the parent process to retrieve
information about its childs
termination.

system calls
A process can wait for one of its
child process to finish by executing
the wait system call.
int wait(int *status)

You might also like