简体   繁体   中英

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?

如果调用wait4()系统调用以在子struct rusage完成时重新获取子struct rusage ,它将使用子ru_utime的资源使用来填充struct rusage结构( ru_utimeru_stime保存子ru_utime使用的用户和系统CPU时间)。

您可以使用getrusage()acct()此处提供更多信息 )系统调用

一种低技术(但简单)的解决方案是定期以批处理模式转储top的输出并在之后解析它。

The time(1) program may help, i guess. It is much simpler than polling top.

An excerpt from the man 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).

You can check the top command. That might be of some help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM