Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Gets the process identification.

int _getpid( void );

Return Value

Returns the process ID obtained from the system. There is no error return.


The _getpid function obtains the process ID from the system. The process ID uniquely identifies the calling process.


Routine Required header Compatibility
_getpid <process.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_getpid.c
/* This program uses _getpid to obtain
 * the process ID and then prints the ID.

#include <stdio.h>
#include <process.h>

int main( void )
   /* If run from command line, shows different ID for 
    * command line than for operating system shell.
   printf( "Process id: %d\n", _getpid() );

Sample Output

Process id: 3584

See Also

Process and Environment Control Routines | _mktemp | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft