.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .TH GETPID 2 2014-09-21 "Linux" "Linux Programmer's Manual" .SH NAME getpid, getppid \- get process identification .SH SYNOPSIS .B #include .br .B #include .sp .B pid_t getpid(void); .br .B pid_t getppid(void); .SH DESCRIPTION .BR getpid () returns the process ID of the calling process. (This is often used by routines that generate unique temporary filenames.) .BR getppid () returns the process ID of the parent of the calling process. .SH ERRORS These functions are always successful. .SH CONFORMING TO POSIX.1-2001, 4.3BSD, SVr4. .SH NOTES Since glibc version 2.3.4, the glibc wrapper function for .BR getpid () caches PIDs, so as to avoid additional system calls when a process calls .BR getpid () repeatedly. Normally this caching is invisible, but its correct operation relies on support in the wrapper functions for .BR fork (2), .BR vfork (2), and .BR clone (2): if an application bypasses the glibc wrappers for these system calls by using .BR syscall (2), then a call to .BR getpid () in the child will return the wrong value (to be precise: it will return the PID of the parent process). .\" The following program demonstrates this "feature": .\" .\" #define _GNU_SOURCE .\" #include .\" #include .\" #include .\" #include .\" #include .\" .\" int .\" main(int argc, char *argv[]) .\" { .\" /* The following statement fills the getpid() cache */ .\" .\" printf("parent PID = %ld\n", (long) getpid()); .\" .\" if (syscall(SYS_fork) == 0) { .\" if (getpid() != syscall(SYS_getpid)) .\" printf("child getpid() mismatch: getpid()=%ld; " .\" "syscall(SYS_getpid)=%ld\n", .\" (long) getpid(), (long) syscall(SYS_getpid)); .\" exit(EXIT_SUCCESS); .\" } .\" wait(NULL); .\"} See also .BR clone (2) for discussion of a case where .BR getpid () may return the wrong value even when invoking .BR clone (2) via the glibc wrapper function. .SH SEE ALSO .BR clone (2), .BR fork (2), .BR kill (2), .BR exec (3), .BR mkstemp (3), .BR tempnam (3), .BR tmpfile (3), .BR tmpnam (3), .BR credentials (7), .BR pid_namespaces (7) .SH COLOPHON This page is part of release 3.74 of the Linux .I man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at \%http://www.kernel.org/doc/man\-pages/.