: UNIX

8.2 ,

8.2 ,

, : stime, time, times alarm. , .

stime . time:

time(tloc);

tloc , , . , , date, , .

times , , . :

times(tbuffer)

struct tms *tbuffer;

tms , :

struct tms {

/* time_t , */

time_t tms_utime; /* */

time_t tms_stime; /* */

time_t tms_cutime; /* */

time_t tms_cstime; /* */

};

times , " ", , .

#include sys/types.h
#include sys/times.h
extern long times();
main() {
int i;
/* tms , 4 */
struct tms pb1, pb2;
long pt1, pt2;
pt1 = times(&pb1);
for (i = 0; i 10; i++) if (fork()== 0) child(i);
for (i = 0; i 10; i++) wait((int*) 0);
pt2 = times(&pb2);
printf("-: %u %u %u : %u %un",
pt2- pt1, pb2.tms_utime- pb1.tms_utime, pb2.tms_stime- pb1.tms_stime, pb2.tms_cutime- pb1.tms_cutime, pb2.tms_cstime- pb1.tms_cstime);
}
child(n)
int n;
{
int i;
struct tms cb1, cb2;
long t1, t2;
t1 = times(&cb1);
for (i = 0; i 10000; i++);
t2 = times(&cb2);
printf(" %d: %u %u %un",
n, t2- t1, cb2.tms_utime- cb1.tms_utime, cb2.tms_stime- cb1.tms_stime);
exit();
}

8.7. , times

8.7 , - 10 , 10000 . - times , . - , , - . , , fork exit, .

alarm ("") . , 8.8 , , . , stat, , , . signal , alarm 60 pause . 60 , wakeup, , pause, .

, (). , .


: 0.108. /Cache: 5 / 0