Debian Codegraph @

listings/chapter-8/print-cpu-times.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <stdio.h>
8 #include <sys/resource.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11
12 void print_cpu_time()
13 {
14 struct rusage usage;
15 getrusage (RUSAGE_SELF, &usage);
16 printf ("CPU time: %ld.%06ld sec user, %ld.%06ld sec system\n",
17 usage.ru_utime.tv_sec, usage.ru_utime.tv_usec,
18 usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
19 }