简体   繁体   English

如何获得一个进程的pid?

[英]How to get a pid of a process?

I want to create a function like this but with priority. 我想创建一个像这样但具有优先级的函数。 For that, I need the pid, but I don't know how to get it. 为此,我需要该pid,但我不知道如何获取它。 Any idea? 任何想法?

Mine is to use setpriority (0, pid, value) , but I need the pid. 我的是使用setpriority (0, pid, value) ,但是我需要pid。

void cmd_exec(char * tr[]) {
    if (execvp(tr[0], tr)== -1)
        perror("Error");
}

To get the process-id of the calling process use getpid() . 要获取调用进程的进程ID,请使用getpid()

Please find the 请找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM