一、接口介绍
getpid()获取当前进程号
getppid()获取父进程号
#include <sys/types.h>
#include <unistd.h>
pid_t getpid(void);
pid_t getppid(void);
返回值:
getpid() returns the process ID of the calling process.
getppid() returns the process ID of the parent of the calling process.
These functions are always successful.
二、举例
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <errno.h>
void *thread_1(void *args)
{
pid_t pid;
pid = getpid();
printf("thread 1 getpid : %d\n",pid);
}
void *thread_2(void *args)
{
pid_t pid;
pid = getpid();
printf("thread 2 getpid: %d\n",pid);
}
int main(int argc,char** argv)
{
pid_t pid;
pth