-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.c
45 lines (38 loc) · 1.08 KB
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
//user program time
int main(int argc, char *argv[]) {
int a = fork();
if(argc!=1){
if (a == 0) {
if(exec(argv[1], argv + 1)<0){
printf(1,"Error in fork\n");
exit();
}
}
else {
int *wtime = (int *)malloc(sizeof(int)), *rtime = (int *)malloc(sizeof(int));
int status = waitx(wtime, rtime);
printf(1, "Run Time: %d, Waiting Time: %d, Returned: %d\n", *rtime, *wtime, status);
}
exit();
}
else{
if (a == 0) {
int b=1;
for(int i=0;i<=1e7;i++){
b+=2; //useless calculations, just to test waitx
}
exit();
}
else {
int *wtime = (int *)malloc(sizeof(int)), *rtime = (int *)malloc(sizeof(int));
int status = waitx(wtime, rtime);
printf(1, "Run Time: %d, Waiting Time: %d, Returned: %d\n", *rtime, *wtime, status);
}
exit();
}
exit();
}