I need to access some information from all of the processes of PID > 1024. Currently, I have used the /proc file-system to put together an array containing all of those process ID's. The code is as follows:
Code:
int main(int argc, char * argv[])
{
char * path = "/proc/";
struct task_struct *info;
struct dirent **namelist;
int i, x, y, procs = 0;
int n = scandir(path, &namelist, 0, alphasort);
int proclist[n];
char * file_name;
for( i = 0; i < n; i++ )
{
if(atoi(namelist[i]->d_name) >= 1024)
{
proclist[procs] = atoi(namelist[i]->d_name);
procs++;
}
}
printf("%d total processes.\n", procs);
for(i = 0; i < procs; i++)
{
printf("%d\n", proclist[i]);
}
return 0;
}
Using the /proc file-system, how can I get information (possibly from "current"), such as PID, GID, running time, etc. about each process?
Is there some way to set a struct task_struct *current = /path/<pid>/attr/current?