#include
#include
#include
void main()
{
struct rusage usage;
getrusage (RUSAGE_SELF, &usage);
printf (“CPU time: %ld.%06ld sec user, %ld.%06ld sec system\n”,
usage.ru_utime.tv_sec, usage.ru_utime.tv_usec,
usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
}
==> 该程序的运行结果为CPU time: 0.000000 sec user, 0.000000 sec system,都是零正常吗?
[root@fedora chapter-8]# ps -u
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.6/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 399 0.0 0.3 1580 408 tty1 Ss+ Sep12 0:00 /sbin/mingetty
root 400 0.0 0.3 1584 412 tty2 Ss+ Sep12 0:00 /sbin/mingetty
root 401 0.0 0.3 1580 408 tty3 Ss+ Sep12 0:00 /sbin/mingetty
root 402 0.0 0.3 1584 404 tty4 Ss+ Sep12 0:00 /sbin/mingetty
root 403 0.0 0.3 1580 408 tty5 Ss+ Sep12 0:00 /sbin/mingetty
root 404 0.0 0.3 1580 408 tty6 Ss+ Sep12 0:00 /sbin/mingetty
root 407 0.0 1.2 4576 1540 pts/0 Ss Sep12 0:02 -bash
root 32242 0.0 1.2 4576 1532 pts/1 Ss+ Sep13 0:01 -bash
root 12349 0.0 0.7 4176 928 pts/0 R+ 08:27 0:00 ps -u
==> 当前进程是去的上面哪个?
ws00871112 于 2011-11-10 22:21:22发表:
都过了一年了,这。。。正常的,你可以在getrusage()前面加个for循环试试