在C语言中,可以使用getpid()
函数来获取当前进程的PID。该函数位于<unistd.h>
头文件中。
示例代码:
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = getpid();
printf("PID: %d\n", pid);
return 0;
}
在上面的示例中,getpid()
函数将返回当前进程的PID,并将其存储在pid
变量中,然后通过printf()
函数打印出来。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux如何获取进程pid