Example C-1 shows a program that uses the PIOCPSINFO and PIOCUSAGE codes to obtain information about the processes named on the command line. For each process, it prints out several of the fields in these structures.
* printTime - convert a number of seconds to days, hours, minutes, and
* seconds, and print it out.
*/
void
printTime(char *str, time_t secs)
{
int d, h, m, s;
s = secs;
/*
* Simple conversion to days, hours, minutes, seconds.
*/
d = s / 86400;
s = s % 86400;
h = s / 3600;
s = s % 3600;
m = s / 60;
s = s % 60;
/*
* Print the label.
*/
printf("%s: ", str);
/*
* Print the days.
*/
if (d)
printf("%dd", d);
/*
* Print the hours, minutes, and seconds.
*/
printf("%02d:%02d:%02d", h, m, s);
}
% procinfo 12567
Command: /usr/local/bin/emacs appC.sgml
Started at: Wed Mar 29 14:13:34 1995
Process-ID: 12567 Parent Process-ID: 262
Process Group Leader: 12567 Session-ID: 262
User-ID: 40 Group-ID: 1 Priority: 59 Nice: 20
Process Size: 4028 KB Resident Set Size: 700 KB
Process Elapsed Time: 01:17:16 Process User CPU Time: 00:01:35
Process System Call Time: 00:00:25 Process System Trap Time: 00:00:00
Process Page Fault Time: 00:00:02 Process Sleep Time: 01:15:11
Process Stopped Time: 00:00:00
Major Page Faults: 154 Minor Page Faults: 0 Swaps: 0
Input Blocks: 17 Output Blocks: 107 Character I/O: 2004141
System Calls: 150222 Signals Received: 4
Without superuser privileges, this program can obtain information about any process owned by its caller that is not running with set-user-id or set-group-id permissions.