Hello I require following information about process with some PID:
name, ppid, state, #ofOpenFiles, #ofThreads
I know the example of /proc/pid/stat file is like :
15 (watchdog/1) S 2 0 0 0 -1 69239104 0 0 0 0 0 69 0 0 -100 0 1 0 6 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 18446744073709551615 0 0 17 1 99 1 0 0 0 0 0 0 0 0 0 0 0
My current attempt of parsing such file:
FILE *fp;
char buff[255];
fp= fopen("/proc/123/stat", "r");
if(fp == NULL){
}else{
fscanf(fp, "%d %s %c %d %d %d %d %d %u %lu ....", &pid, &name, &ppid......)
fclose(fp);
}
I don't find this very good method. How to do this?
/proc
? – Mccrearystat
file. Just stop at the last field that you are interested in. 2. For any fields that you need to read but don't care about, use the*
format specifier to ignore it so that you don't need to provide a variable to store its value. – Mccreary(
, so the parsing is a little bit more complicated. – Liddell/proc/stat/
is updated with new times? – Salamancamsec()
? – Salamanca