Search code examples
cprocessorder-of-execution

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. Any idea?

Mine is to use setpriority (0, pid, value), but I need the pid.

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

Solution

  • To get the process-id of the calling process use getpid().

    Please find the