Question: This lab will involve writing a C program using the fork() system call that generates the Collatz sequence in the child process. The initial number
This lab will involve writing a C program using the fork() system call that generates the Collatz sequence in the child process. The initial number will be provided in the command line. For example, if your executable program was named lab1, you would enter
./lab1 13
and this would output the Collatz sequence beginning at 13 in the child process.
You will write two versions of this program:
-
This first version outputs the sequence directly in the child process. Name this program lab1a.c
-
The second version - name it lab1b.c - has the child process overlay its address space using the exec() system call with another program that generates the output. This will require that you also write a separate program that generates the sequence - the starting number will also be passed on the command line. Name this separate program collatz.c
If lab1b.c is compiled to lab1b, you will invoke this program with ./lab1b 13 . This program will then fork a separate child process and have the child invoke the collatz program using the exec() system call. (The parameter passed to the original program must be passed through to the child process - this is further explained below.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
