getpid() — Get the process ID
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <unistd.h>
pid_t getpid(void);
General description
Finds the process ID (PID) of the calling process.
Returned value
getpid() returns the found value. It is always successful.
There are no documented errno values.
Example
CELEBG14
/* 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);
}
Output
sending SIGUSR1 to pid 5570567
catcher has control!