PID of a running process in C++
I am writing a code and I want to set CPU affinity of a process for which I need its PID . How can I read the pid of running processes in C++ code.
Any help is appreciable. |
There's a C-library getpid() function that returns the PID of the current process. You can use getppid() to get the PID of the parent.
|
Hi Hazel , thanks for your reply . Actually I am looking for another independent process's id whose I know only the name . Its neither the child or parent process of my program.
|
How about something like this?
Code:
#include <stdio.h> Code:
$ ./myPidof Code:
pidof -s cbatticon http://stackoverflow.com/questions/8...x-in-c#8166467 Best regards, HMW |
Bear in mind, also, that "CPU affinity" is customarily set by rules, or heuristics, which do not presume prior knowledge of a particular PID. The exceptions are low-level system calls which presume that the PID is already known, e.g. by its parent.
|
All times are GMT -5. The time now is 06:04 AM. |