diff options
Diffstat (limited to 'lab05/procs-solution.c')
| -rw-r--r-- | lab05/procs-solution.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lab05/procs-solution.c b/lab05/procs-solution.c new file mode 100644 index 0000000..cf1a9ff --- /dev/null +++ b/lab05/procs-solution.c @@ -0,0 +1,18 @@ +#include <sys/types.h> +#include <unistd.h> +#include <stdio.h> + +int global; + +int main() +{ + if (fork()) { /* only the 1st parent enters here */ + fork(); /* ...to fork() a 2nd child... */ + } + + /* All 3 processes (parent and children) run the following */ + + global = getpid(); /* set to a process-specific value */ + sleep(1); + printf("PID is %d, global = %d\n", getpid(), global); +} |
