-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserprogram.c
More file actions
84 lines (55 loc) · 1.6 KB
/
Copy pathuserprogram.c
File metadata and controls
84 lines (55 loc) · 1.6 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int
main(int args , char *argv[]){
// char* cd = {" ls "};
// char**p = &cd;
// exec("ls" , p);
//1st question
int sum = 0;
for(int i = 0;i < args;++i){
sum += 10;
}
printf(1,"%d",sum);
helloWorld();
//2nd question
printf(1, "Total Number of Open Files: %d\n", numOpenFiles());
int fd;
fd = open("backup", O_CREATE | O_RDWR);
printf(1, "Total Number of Open Files: %d\n", numOpenFiles());
close(fd);
printf(1, "Total Number of Open Files: %d\n", numOpenFiles());
// //3rd question
// printf(2,"Memory allocated");
printf(1,"Memory allocated till now: %d bytes\n", memAlloc());
sleep(90);
char* x = sbrk(1024);
printf(1,"Memory allocated till now: %d bytes\n", memAlloc());
//free(x);
char* y = sbrk(4096);
printf(1,"Memory allocated till now: %d bytes\n", memAlloc());
printf(1,"Memory allocated till now: %d bytes\n", memAlloc());
char* z = sbrk(-10);
printf(1,"Memory allocated till now: %d bytes\n", memAlloc());
char* a = sbrk(-20000);
printf(1,"Memory allocated till now: %d bytes\n", memAlloc());
printf(1,"for process process date time\n ", getprocesstimedetails());
if(fork() == 0){
printf(1,"child forked\n", getprocesstimedetails());
sleep(170);
printf(1,"2nd new process date time\n ", getprocesstimedetails());
sleep(170);
printf(1,"3rd time process date time\n ", getprocesstimedetails());
sleep(170);
}else{
wait(0);
printf(1,"for process process date time\n ", getprocesstimedetails());
}
free(x);
free(y);
free(z);
free(a);
exit(0);
}