From af845ed89d5aea79617c47a504f218b82b901170 Mon Sep 17 00:00:00 2001
From: k2-colambatant <kavishka2.colambatantri@live.uwe.ac.uk>
Date: Thu, 31 Mar 2022 17:20:47 +0100
Subject: [PATCH] - task2.c contains the code snippet used for task 2.

---
 .../task2.c                                   | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Task 2 -  Passing Environment Variables from Parent Process to Child Process/task2.c

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 0000000..fa2d8a3
--- /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
-- 
GitLab