-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc.c
More file actions
35 lines (33 loc) · 1.03 KB
/
proc.c
File metadata and controls
35 lines (33 loc) · 1.03 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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
// #include <string.h>
// #include <sys/wait.h>
// #include <limits.h>
// int main()
// {
// printf("I am process %d\n", (int) getpid());
// char *mem = (char *) calloc(1, 100);
// pid_t child_pid = fork();
// pid_t my_pid = getpid();
// if (child_pid == 0)
// {
// printf("%d: I am child, fork returned %d\n",
// (int) my_pid, (int) child_pid);
// printf("%d: child is terminated with code 100\n",
// (int) my_pid);
// printf("%d: memory values are set to 1\n", (int) my_pid);
// memset(mem, 1, 100);
// return 100;
// }
// printf("%d: I am parent, fork returned %d\n",
// (int) my_pid, (int) child_pid);
// int stat;
// pid_t wait_result = wait(&stat);
// printf("%d: wait returned %d and stat %d\n", (int) my_pid,
// (int) wait_result, stat);
// printf("%d: memory values are %d\n", (int) my_pid, (int) mem[0]);
// printf("%d: returned child code was %d\n", (int) my_pid,
// WEXITSTATUS(stat));
// return 0;
// }