Thread: Displaying Process Information From task_struct?

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Maine
    Posts
    11

    Question Displaying Process Information From task_struct?

    I have to somehow retrieve process information from task_struct and display it in in the terminal, like ps does. However, I may also have to add my own code to the sched.c and sched.h files, so I can't simply use a system call that already exists in my program.

    How might I go about this and what is the best way to access the task_struct information? I have already read numerous threads and web sites, none of which contain much detail. Any help would be appreciated!

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    30
    each process has a task_struct; which processes do you want to access information for? I think usually only the kernel has access to this

    process information is also available in the /proc filesystem, see the proc man page

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    Maine
    Posts
    11
    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?
    Last edited by smoothdogg00; 12-19-2006 at 08:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Killing A Process
    By tommyb05 in forum C Programming
    Replies: 8
    Last Post: 06-01-2009, 06:41 AM
  3. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  4. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM