#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;
}
Getting the run time of a process
Hi guys I''m just starting to play around with processes, below is some extremely basic code of what i''ve done so far.
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.
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement