Skip to content

Commit fb04421

Browse files
committed
cleanup
1 parent 38ec174 commit fb04421

File tree

15 files changed

+104
-105
lines changed

15 files changed

+104
-105
lines changed

s5/os/1.1.exitsyscall.c

Lines changed: 0 additions & 12 deletions
This file was deleted.

s5/os/1.2.opnclosesyscall.c

Lines changed: 0 additions & 22 deletions
This file was deleted.

s5/os/1.3.fork.c

Lines changed: 0 additions & 20 deletions
This file was deleted.

s5/os/1.4.getpid.c

Lines changed: 0 additions & 12 deletions
This file was deleted.

s5/os/1.5.statsyscall.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

s5/os/1.6.exec_system_call/1.6.1.execlsyscall.c

Lines changed: 0 additions & 12 deletions
This file was deleted.

s5/os/1.a.exit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int main() {
5+
for (int i = 0;i <= 7;i++) {
6+
if (i == 5) exit(0);
7+
else printf("%d\n", i);
8+
}
9+
return 0;
10+
}

s5/os/1.b.opnclose.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <fcntl.h>
2+
#include <stdio.h>
3+
#include <unistd.h>
4+
5+
int main() {
6+
int fd = open("foo.txt", O_RDONLY | O_CREAT);
7+
8+
printf("fd = %d\n", fd);
9+
10+
if (fd == -1) printf("Error\n");
11+
else printf("file opened\n");
12+
13+
if (close(fd) == -1) printf("Error\n");
14+
else printf("file closed\n");
15+
16+
return 0;
17+
}

s5/os/1.c.forkwait.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int x = 1;
5+
int k = fork(); // Creates a new process
6+
7+
if (k < 0) printf("Error\n");
8+
else if (k == 0) printf("Child has x = %d\n", ++x); // Child process increments x
9+
else {
10+
wait(1000); // Parent process waits for child process to finish
11+
printf("Parent has x = %d\n", --x); // Parent process decrements x
12+
}
13+
14+
return 0;
15+
}

s5/os/1.d.getpid.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int x = 1;
5+
int pid = fork(); // Creates a new process
6+
7+
if (pid == 0) printf("Process id of Child = %d\n", getpid()); // Child process prints its PID
8+
else printf("Process id of parent = %d\n", getppid()); // Parent process prints its parent's PID
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)