Question
Programming Assignment 2 Objective: The objective of this assignment is to familiarize yourself with the notion of a process and the system call fork( )
Programming Assignment 2
Objective: The objective of this assignment is to familiarize yourself with the notion of a process and the system call fork( ) used to create a new process.
Assignment: Using the Fork System Call The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm:
The conjecture states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is: 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1 The idea is to write a C program using the fork() system call that generates this sequence in the child process. The starting number will be provided from the command line. For example, if 8 is passed as a parameter on the command line, the child process will output 8, 4, 2, 1. Because the parent and child processes have their own copies of the data, it will be necessary for the child to output the sequence. Have the parent invoke the wait() call to wait for the child process to complete before exiting the program.
Collatz Program Implementation: The collatz program (collatz.c) is a simple text-based program that takes one argument from the command line, again no prompting the user from within the program.
1. To start the collatz program ./collatz where is the starting number (n) for the collatz conjecture.
Error Handling: Perform the necessary error checking to ensure that a positive integer is passed on the command line.
Grading:The program will be graded on the basic functionality, error handling and how well the implementation description was followed. Be sure to name your program collatz.c (no extra characters, capitals) Note that documentation and style are worth 10% of the assignment's grade!
n = 1 n/2, if n is even 3 x n+1, ifn is oddStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started