diff --git a/Task 2 - Passing Environment Variables from Parent Process to Child Process/task2.c b/Task 2 - Passing Environment Variables from Parent Process to Child Process/task2.c new file mode 100644 index 0000000000000000000000000000000000000000..fa2d8a3e9804202884bf40c900750d39096faa8c --- /dev/null +++ b/Task 2 - Passing Environment Variables from Parent Process to Child Process/task2.c @@ -0,0 +1,29 @@ +//STUDENT ID: 20042129 +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> + +//Access environment variables +extern char **environ; + +void printenv() +{ + int i = 0; + while (environ[i] != NULL) { + printf("%s\n", environ[i]); + i++; + } +} + +void main() +{ + pid_t childPid; + switch(childPid = fork()) { + case 0: /* child process */ + //printenv(); // (1) + exit(0); + default: /* parent process */ + printenv(); //(2) + exit(0); + } +} \ No newline at end of file