LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-19-2006, 07:57 PM   #1
smoothdogg00
Member
 
Registered: Feb 2006
Location: Maine
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 15
Question Using /proc to access process information from a program?


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?

Last edited by smoothdogg00; 12-19-2006 at 08:01 PM.
 
Old 12-20-2006, 01:37 PM   #2
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
I am a bit confused by your post. First of all, I do not quite understand why you'd want to do something like that in the first place (homework assignments aside). Further, it seems that information is abundantly available in google (try "proc filesystem process information"), and there is a pile of example applications doing exactly this (try downloading the procps package source code. It contains the code to the ps command.

This makes me wonder what you have already tried to get your question answered, and where you get stuck?

Groetjes,

Kees-Jan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What /proc file(s) have process information pat_and_cami Programming 3 03-09-2006 05:18 PM
What /proc file(s) have process information pat_and_cami Suse/Novell 1 03-08-2006 12:17 PM
Is /proc hw information really that accurate? jimieee Linux - General 5 03-06-2006 07:58 AM


All times are GMT -5. The time now is 09:49 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration