I would like to read and print the status of pid of a process in linux using C.
for(p=0; p<=j; ++p)
{
char buf[512];
FILE *process = popen("pidof -s process[j]", "r");//process[j] contains the cmd line
fgets(buf, 512,process);
pid_t pid = strtoul(buf, NULL, 10);
printf("%s",buf,512);
p=pid;
char status= fscanf("/proc/[pid]/stat", "%s", buf[512]);
}
i.e. I would like the status of the process to be printed.
I was able to read the pid of the processes. But I failed in reading the status from:
/proc/[pid]/stat
And printing the status of the process.