Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring process statistics in Linux

I am building programming contest software. A user's program is received by our judging system and is evaluated by compiling it and running it via a fork() and exec(). The parent process waits for the child (submission's process) to exit, and then cleans it up.

To give useful information about the program's run, I want to measure the CPU time and peak memory used by the program. Does the Linux kernel keep track of these values? Is there any other way to get this information?

like image 207
donatello Avatar asked Mar 03 '10 10:03

donatello


People also ask

What is Pidstat Linux?

Pidstat is a command-line tool and part of sysstat suite to monitor the Linux system. It is used to monitor every individual task currently being managed by the Linux kernel on the Linux system.

What is Proc Statm?

/proc/[pid]/statm Provides information about memory usage, measured in pages.


1 Answers

If you call the wait4() system call to reap the child when it finishes, it will fill out a struct rusage structure with the resource usage of the child (ru_utime and ru_stime hold the user and system CPU time used by the child respectively).

like image 101
caf Avatar answered Oct 18 '22 19:10

caf