gtpc2m4fC/C++ Language Support User's Guide

kill-Send a Signal to a Process

This function permits signals to be sent to another entry control block (ECB).

Format

#define _POSIX_SOURCE
#include <signal.h>
pid_t kill(pid_t pid, int sig);

pid
The process identifier (ID) of the process that receives the signal from the kill function.

sig
One of the macros defined in the signal.h header file or 0. The signals that are supported are listed in Table 13. If you specify a value of 0, error checking is performed, but a signal is not sent. Code sig as 0 to check whether the pid argument is valid.

Normal Return

If successful, a value of 0 is returned.

Error Return

If unsuccessful, the kill function returns a value of -1 and sets errno to one of the following:

EINVAL
The value of the sig argument is an incorrect or unsupported signal number.

EPERM
The process does not have permission to send the signal to the receiving process.

ESRCH
The process specified by the pid parameter cannot be found.

Programming Considerations

Examples

The following example shows how to send sig SIGTERM.

#include <stdio.h>
#include <stdlib.h>
#define _POSIX_SOURCE
#include <signal.h>

·
·
·
pid_t child_pid; /* Create a child process*/
·
·
·
child_pid = tpf_fork(&create_parameters);
·
·
·
/* Signal child process to terminate*/ if (kill (child_pid, SIGTERM) == -1) { if (errno == ESRCH) { printf("Could not find child"); abort(); } }

Related Information