Linux measurement process statistics

I am creating programming software. The user program is obtained by our judging system and is evaluated by compiling it and running it through fork () and exec (). The parent process waits for the child (sending process) to exit and then clear it.

To provide useful information about starting a program, I want to measure the processor time and peak memory used by the program. Is the Linux kernel tracking these values? Is there any other way to get this information?

+6
c linux statistics linux-kernel operating-system
source share
5 answers

If you call the wait4() system call to get the child when it finishes, it populates the struct rusage structure using the child's resource ( ru_utime and ru_stime holds the user and system CPU time used by the child, respectively).

+6
source share

You can use getrusage() or acct() ( more getrusage() here ) syscalls

+5
source share

A low-tech (but simple) solution is to periodically unload the top output in batch mode and analyze it later.

0
source share

A time program (1) may help, I think. This is a lot easier than polling.

Excerpt from the manual page:

  Disregarding the name of the utility, GNU makes it output lots of useful information, not only about time used, but also on other resources like memory, I/O and IPC calls (where available). 
0
source share

You can check the top command. This can help.

-one
source share

All Articles