Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 12-19-2006, 07:57 PM   #1
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:
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);

  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
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?




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 / openSUSE 1 03-08-2006 12:17 PM
Is /proc hw information really that accurate? jimieee Linux - General 5 03-06-2006 07:58 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 PM.

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