1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH GETPID 2 2014-09-21 "Linux" "Linux Programmer's Manual"
27 getpid, getppid \- get process identification
29 .B #include <sys/types.h>
31 .B #include <unistd.h>
33 .B pid_t getpid(void);
35 .B pid_t getppid(void);
38 returns the process ID of the calling process.
39 (This is often used by
40 routines that generate unique temporary filenames.)
43 returns the process ID of the parent of the calling process.
45 These functions are always successful.
47 POSIX.1-2001, 4.3BSD, SVr4.
49 .SS C library/kernel ABI differences
50 Since glibc version 2.3.4,
51 the glibc wrapper function for
54 so as to avoid additional system calls when a process calls
57 Normally this caching is invisible,
58 but its correct operation relies on support in the wrapper functions for
63 if an application bypasses the glibc wrappers for these system calls by using
67 in the child will return the wrong value
68 (to be precise: it will return the PID of the parent process).
69 .\" The following program demonstrates this "feature":
71 .\" #define _GNU_SOURCE
72 .\" #include <sys/syscall.h>
73 .\" #include <sys/wait.h>
74 .\" #include <stdio.h>
75 .\" #include <stdlib.h>
76 .\" #include <unistd.h>
79 .\" main(int argc, char *argv[])
81 .\" /* The following statement fills the getpid() cache */
83 .\" printf("parent PID = %ld\n", (long) getpid());
85 .\" if (syscall(SYS_fork) == 0) {
86 .\" if (getpid() != syscall(SYS_getpid))
87 .\" printf("child getpid() mismatch: getpid()=%ld; "
88 .\" "syscall(SYS_getpid)=%ld\n",
89 .\" (long) getpid(), (long) syscall(SYS_getpid));
90 .\" exit(EXIT_SUCCESS);
96 for discussion of a case where
98 may return the wrong value even when invoking
100 via the glibc wrapper function.
111 .BR pid_namespaces (7)