gtpc2m4f | C/C++ Language Support User's Guide |
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
- For a process to have permission to send a signal to another process, the
real or saved set-user-ID (UID) of the sending process must match the real or
saved set-user-ID of the receiving process, or the sending process must have
superuser privileges.
- Some TPF system events trigger the internal creation of a signal; for
example, the exit of a child ECB that was created by the tpf_fork
function results in a sig SIGCHLD returned to the parent.
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