Professional Documents
Culture Documents
Signals 2
Signals 2
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);
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.
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.
ß
#include<unistd.h>
unsigned int alarm (unsigned int seconds);
Returns: 0 or number of seconds until previously set alarm.
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.
Syntax
Syntax
#include <signal.h>
int sigpending(sigset_t *set);
Returns:0 if Ok, -1 on error.
abort function
Syntax
#include<stdlib.h>
void abort(void);
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.
#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.
/* alternate handler */
void (*sa_sigaction)(int, siginfo_t *, void *);
};