Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C Please. You will create (fork) two processes to print their respective sequence for the Collatz conjecture. The first will produce the sequence which

In C Please.

image text in transcribed

You will create (fork) two processes to print their respective sequence for the Collatz conjecture. The first will produce the sequence which is indicated by the number on the command line and the second process will produce the sequence from the command line number plus 4. Please print " child (1 or 2) " with each number output and be sure the forked processes can run concurrently.

You will need to use stdlib.h if you want to use 'atoi' to translate a character string into an integer.

Use 'sprintf' to put values into strings.

You will need to do wait twice so that the main program finishes after the children (no cascading termination).

You will need to use argc and argv to get command line arguments.

The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm: n={n/2,3n+1,ifnisevenifnisodd 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 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. Perform necessary error checking to ensure that a positive integer is passed on the command line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

A round nose tool has no back rake and side rake. Correct Incorrect

Answered: 1 week ago