Question: Help in C please: Using C programming language, write a program named asg1.c. The program will take two integers and a character string as command

Help in C please:

Using C programming language, write a program named asg1.c. The program will take two integers and a character string as command line arguments. You should give an error message, if user did not provide the required command line arguments, and exit the program. In your program you will create a struct that has two integer members num1 and num2 and a char string message. They will be initialized to the CL arguments provided by the user. Your program will have three processes that can be created by cleverly using the fork() system call. The first child will be given its own routine to execute. This routine is called area and the code for this routine lives in the file named area.c. This can be accomplished by passing the name of the executable file (along with other necessary arguments) to the execl(...) call. Please study the examples in Files/code_examples/processes folder. This routine will calculate the square area by multiplying num1 and num2. It will then print its own pid, its parents pid, the result of the calculation to the standard output (as shown below) and exit. The second child will execute its own routine. This routine is called perimeter and the code for this routine lives in the file named perimeter.c. As above, this will be accomplished by passing the name of the executable file (along with other necessary arguments) to the execl(...) call. This routine will calculate the perimeter by using variables num1 and num2. It will then print its own pid, parent pid, the result to the standard output and will exit. The parent will create two threads. Each thread will take a pointer to a function and your struct as parameters to thread creation call. The first thread will calculate the ratio of the two numbers by dividing num1 by num2, and will return that result to the parent via thread_exit call. The second thread will reverse the message string, and also pass the reversed string to the parent. Each thread will print its own tid and the result of the calculation/reversal to standard output before returning result to the parent. 2. Normally, if you have a number of processes, each may be scheduled to run at a different time, may be preempted at least once, and their output may be interleaved. In your program you will need to figure out a way for your processes to produce output that is not interleaved. (hint a process can be put to sleep to allow other process to finish printing, you do not need to use any locks or Cvs for synchronization ) 3. When you execute your program, your output should be exactly as the one shown below, with the exception of the process ids - those will be different from the ones shown. 4. Do not forget that the parent process needs to wait for all the children to finish executing. Process-creating threads needs to call join on each thread as well

Output: (your pids/tids will be different than the ones shown below) Child1: pid 39810, ppid 39809, area is 50 Child2: pid 39811, ppid 39809, perimeter is 30 Thread 1: tid 12345678, ratio is 2 Thread 2: tid 23456789, message is sregiToG Parent: pid 39809, ratio: 2, message: sregiToG

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!