From 219fba47ef556eb21f60bb5863b8badf6722e380 Mon Sep 17 00:00:00 2001 From: Trevor Lewis Date: Thu, 4 Apr 2019 16:04:38 -0700 Subject: [PATCH] Got through 2 examples. Going through more tonight --- ex1/ex1.c | 14 ++++++++++++++ ex2/ex2.c | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ex1/ex1.c b/ex1/ex1.c index c4b111641..510eef9d2 100644 --- a/ex1/ex1.c +++ b/ex1/ex1.c @@ -10,5 +10,19 @@ int main(void) { // Your code here + pid_t pid = fork(); + + if (pid == 0) + { + int x = 200; + printf("\n This is the child, x = %d\n", x); + exit(1); + } + else + { + int x = 100; + printf("\n This is the parent, x = %d\n", x); + } + return 0; } diff --git a/ex2/ex2.c b/ex2/ex2.c index 4245375b9..abe638b9e 100644 --- a/ex2/ex2.c +++ b/ex2/ex2.c @@ -8,7 +8,21 @@ int main(void) { - // Your code here - + // Your code here + pid_t pid = fork(); + FILE *fp; + fp = fopen("text.txt", "w+"); + + if (pid == 0) + { + + fprintf(fp, "\n I\'m printing from the child\n"); + exit(1); + } + else + { + fprintf(fp, "\n I\'m printing from the parent\n"); + } + return 0; }