Reputation: 123
In my project, we use the ACE ( Adaptive Communication Environment) middleware to write OS independent code that would run on both Windows and Linux.
The requirement is to the get the process id from process name. Since ACE does not support this, we will have to use platform specific macros to separate the code for windows and linux.
For windows I would have to use either of - EnumProcesses or CreateToolhelp32Snapshot
How to do the same on linux using an API ?
Programming language is C++
Upvotes: 0
Views: 2002
Reputation: 944
if i understand your question correctly, you can do this from c++
char buf[512];
FILE *cmd_pipe = popen("pidof -s process_name", "r");
fgets(buf, 512, cmd_pipe);
pid_t pid = strtoul(buf, NULL, 10);
pclose( cmd_pipe );
here is an another example: Get process id by name in Linux using C++
Upvotes: 1