Advertisement

Getting the run time of a process

Started by March 15, 2002 08:34 AM
2 comments, last by pdstatha 22 years, 6 months ago
Hi guys I''m just starting to play around with processes, below is some extremely basic code of what i''ve done so far.
  
#include <unistd.h>
#include <sys/types.h>

int main(void){
  pid_t child,parent;
  char *term;
  child = getpid();
  parent = getppid();
  term = ctermid((char*)child);
  printf("Child: %d\n",child);
  printf("Parent: %d\n",parent);
  printf("Terminal: %s\n",term);
  return 0;
}  
I was just wondering how would you get the run time of a process, as I am trying to figure out how "ps" does its stuff.
By reading the /proc directory

joeG
joeG
Advertisement
Please elaborate, there is quite a bit of stuff in the proc directory, what should I be looking for?
M''kay, first ls -al /proc and look at the list of all directories in /proc that contain numerical names. Each directory with a numerical name is the number of the process. Now say for example you are interested in the process specified by /proc/12345, type ls -al /proc/12345 and you should see a bunch of interesting objects (files, subdirs, links, etc). Each object contains information about that process which the ps command obtains its information from. Now all you need to do is open the file and read the information. You can manually do that by using the command more, ie more /proc/12345/mem for example.
Tara Milana - WP Entertainmenthttp://wolfpack.twu.net/Comp graphics artist and programmer.

This topic is closed to new replies.

Advertisement