Home > Net >  where is psinfo_t struct in linux library?
where is psinfo_t struct in linux library?

Time:04-09

i used "psinfo_t" struct for printing cpu usage, start time of the processes in Solaris. But our companie's server was moved to Linux(Red Hat Linux), so i can't compile my c code because it has psinfo_t struct. where can i find that?

CodePudding user response:

On Solaris (proc(5)), psinfo_t is a type found in <procfs.h>.

This does not exist on Linux, and the two /proc filesystems have various differences.

Under Linux (proc(5)), /proc/[pid]/stat contains the usual information found with ps(1).

Here is the simplest of examples, printing information about the current process.

#include <stdio.h>

int main(void) {
    FILE *self = fopen("/proc/self/stat", "r");
    char buffer[512];

    while (fgets(buffer, sizeof buffer, self))
        printf("%s", buffer);

    fclose(self);
}
  • Related