*Help Please with the code** CSIT 345 Lab 2 Process Programming Your lab requirement is to write program codes for 3.21 and shared memory program for producer and consumer as shown in the following. You can start with the code provided in the virtual machine in the virtual box you installed. The code can be found in /home/oscreader/osc9e-src/ch3 a. For 3.21, you can start with the newprocposix.c and modify the code to meet your requirement. Then type: gcc neypCOCROSİS.c to compile, then type ./a.outto execute Programming Problems 155 321 The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm: if n is even n/2 3 x n+1, if n is odd 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 forkO 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 mecessary for the child to output the sequence. Have the parent invoke the wait() call to wait for the child process the ne program. Perform necessary error checking to ensure that a int to complete before exiting positive er is passed on the command line. output the sequence of s must b. You will write two programs, producer and consumer. The producer will generate the sequence of numbers using Collatz conjecture and write it to the shared memory. The consumer will read the sequence of number out from the shared memory. Please start with the code under /osc9e-src/ch3: shm-posix-consumer.c and shm-posix producer.c as the template. Modify the code as needed to fit your needs. When you compile the code, please run the following two commands: gcc_shm posix-consumer.c-o consumer -lrt gcc shm-posix-producer.c-o producer lrt Then you should type-/producer to execute the producer program and then type ./consumer to execute the consumer program. The consumer program will print out the number sequence on the screen. CSIT 345 Lab 2 Process Programming Your lab requirement is to write program codes for 3.21 and shared memory program for producer and consumer as shown in the following. You can start with the code provided in the virtual machine in the virtual box you installed. The code can be found in /home/oscreader/osc9e-src/ch3 a. For 3.21, you can start with the newprocposix.c and modify the code to meet your requirement. Then type: gcc neypCOCROSİS.c to compile, then type ./a.outto execute Programming Problems 155 321 The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm: if n is even n/2 3 x n+1, if n is odd 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 forkO 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 mecessary for the child to output the sequence. Have the parent invoke the wait() call to wait for the child process the ne program. Perform necessary error checking to ensure that a int to complete before exiting positive er is passed on the command line. output the sequence of s must b. You will write two programs, producer and consumer. The producer will generate the sequence of numbers using Collatz conjecture and write it to the shared memory. The consumer will read the sequence of number out from the shared memory. Please start with the code under /osc9e-src/ch3: shm-posix-consumer.c and shm-posix producer.c as the template. Modify the code as needed to fit your needs. When you compile the code, please run the following two commands: gcc_shm posix-consumer.c-o consumer -lrt gcc shm-posix-producer.c-o producer lrt Then you should type-/producer to execute the producer program and then type ./consumer to execute the consumer program. The consumer program will print out the number sequence on the screen.
-
Engineering 2022-05-15 19:04:59