用户态获取进程ID
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
// 获取当前进程的PID
pid_t pid = getpid();
// 获取当前进程的PPID
pid_t ppid = getppid();
获取线程PID:
#include <pthread.h>
TaskID = (pthread_t)(pthread_self());
内核态获取进程ID:
变量方法:
current->pid;,线程ID
current->tgid;,进程ID
current 不需要额外声明定义;内核变量;
函数方法:
sys_getpid,进程ID
sys_gettid,线程ID