0
votes

So I have a job for my OS class and one of the increased value options it to add, when listing the process ID and name of the commands I have running, the CPU time and the real usage time of the same commands. Thing is, I can only get them after they have finished, using the times() function and the information is supposed to appear while they are running. Is there any way to do this?

I am launching commands by forking the parent process and then running execlp("xterm","xterm","-hold", "-e", command, NULL) on the child. As you can see, the -hold prevents the window from closing instantly, which, on the one hand, ables me to see the output of a date command, for example, but on the other hand makes the xterm hang until I close it with either kill() or directly on the xterm window.

All help is appreciated. Thank you. :)

Note: The OS is Linux (I'm using Ubuntu 11.04 but the code should work on all distros).

1

1 Answers

1
votes

You can read this information from /proc/pid/stat, where pid is the process ID that you're interested in.

See the proc man pages for details.

Look also at ps -o format, which allows you to select the fields that ps should display. Again, see the man pages for details.