Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <unistd.h>
pid_t getpid(void);
Finds the process ID (PID) of the calling process.
getpid() returns the found value. It is always successful.
There are no documented errno values.
⁄* CELEBG14 *⁄
#define _POSIX_SOURCE
#include <stdio.h>
#include <sys⁄types.h>
#include <signal.h>
#include <unistd.h>
void catcher(int signum) {
puts("catcher has control!");
}
main() {
struct sigaction sact;
sigemptyset(&sact.sa_mask);
sact.sa_flags = 0;
sact.sa_handler = catcher;
sigaction(SIGUSR1, &sact, NULL);
printf("sending SIGUSR1 to pid %d\n", (int) getpid());
kill(getpid(), SIGUSR1);
}
sending SIGUSR1 to pid 5570567
catcher has control!