Answered step by step
Verified Expert Solution
Question
1 Approved Answer
needed in. C ASAP . Begin by writing a recursive C function that calculates the nth fibonacci number, this will be used in the main
needed in. C ASAP
. Begin by writing a recursive C function that calculates the nth fibonacci number, this will be used in the main assignment problem. The fibonacci numbers are a sequence given by: f1 = 1, f2 = 1, fn = fn-1 + fn-2, for n > 3 Write a C program that generates a timer profile of the current process. Your time measurements should have seconds, and microseconds accuracy. It should be able to display four (4) different timer measurements for the current process: Wall Time Spent Executing - The amount of time the process spent from start to finish. (i.e. the Real Time) Total Time Spent on CPU - The amount of time the process spent executing instructions on the CPU plus the amount of time that the kernel was doing work on behalf of the process. (i.e. the Profile Time) Time Spent in User Space - The amount of time the process spent executing instructions on the CPU.(i.e. the Virtual Time) Time Spent in Kernel Space - The amount of time the kernel spent doing work on behalf of the process. For each interval that you wish to record, set up an interval timer that raises a signal every one (1) second. Each second, when the signal is raised, some counter should be used to keep track of the number of seconds that have elapsed. In the end, the counter together with the present contents of the given interval timer will be sufficient to obtain the number of seconds and microseconds that have elapsed since the process began. Write the code for profiling the process in a general manner so that it can be re-used for multiple processes. This will be necessary for the next part of the assignment given below. Next adjust your program so that it spawns new processes. The main program (the parent process) should spawn a first child that is given to compute the nth fibonacci number, where n is the second command line parameter (i.e. argv[2]). Immediately after spawning the first child. the parent should spawn a second child that is given to compute the mth fibonacci number, where m is the third command line parameter (i.e. argv[3]). After spawning the second child, the parent itself should then proceed to compute the fibonacci number for the first command line parameter (i.e. argv[1]). After the parent has finished computing, it should wait on the first and second child processes to complete before continuing. After each child has finished computing its assigned fibonacci number, it's timer profile should be printed. The parent's profile should be printed after it has done waiting on the children. Your program should be called Fibonacci_timers.c. Following is an example of how such a program should work. $ ./fibonacci_timers 43 44 45 [Child 1] fibonacci (44) = 701408733 Wall Time Spent Executing : 42 seconds, 440000 microseconds Total Time Spent on CPU : 15 seconds, 290000 microseconds Time Spent in User-Space : 15 seconds, 280000 microseconds Time Spent in Kernel-Space: 0 seconds, 10000 microseconds (Child 2] fibonacci (45) = 1134903170 Wall Time Spent Executing : 52 seconds, 310000 microseconds Total Time Spent on CPU : 24 seconds, 310000 microseconds Time Spent in User-Space : 24 seconds, 220000 microseconds Time Spent in Kernel-Space: 0 seconds, 90000 microseconds [Parent] fibonacci (43) = 433494437 Wall Time Spent Executing : 52 seconds, 1000000 microseconds Total Time Spent on CPU : 9 seconds, 1000000 microseconds Time Spent in User-Space : 9 seconds, 1000000 microseconds Time Spent in Kernel-Space: 0 seconds, Omicroseconds $ . Begin by writing a recursive C function that calculates the nth fibonacci number, this will be used in the main assignment problem. The fibonacci numbers are a sequence given by: f1 = 1, f2 = 1, fn = fn-1 + fn-2, for n > 3 Write a C program that generates a timer profile of the current process. Your time measurements should have seconds, and microseconds accuracy. It should be able to display four (4) different timer measurements for the current process: Wall Time Spent Executing - The amount of time the process spent from start to finish. (i.e. the Real Time) Total Time Spent on CPU - The amount of time the process spent executing instructions on the CPU plus the amount of time that the kernel was doing work on behalf of the process. (i.e. the Profile Time) Time Spent in User Space - The amount of time the process spent executing instructions on the CPU.(i.e. the Virtual Time) Time Spent in Kernel Space - The amount of time the kernel spent doing work on behalf of the process. For each interval that you wish to record, set up an interval timer that raises a signal every one (1) second. Each second, when the signal is raised, some counter should be used to keep track of the number of seconds that have elapsed. In the end, the counter together with the present contents of the given interval timer will be sufficient to obtain the number of seconds and microseconds that have elapsed since the process began. Write the code for profiling the process in a general manner so that it can be re-used for multiple processes. This will be necessary for the next part of the assignment given below. Next adjust your program so that it spawns new processes. The main program (the parent process) should spawn a first child that is given to compute the nth fibonacci number, where n is the second command line parameter (i.e. argv[2]). Immediately after spawning the first child. the parent should spawn a second child that is given to compute the mth fibonacci number, where m is the third command line parameter (i.e. argv[3]). After spawning the second child, the parent itself should then proceed to compute the fibonacci number for the first command line parameter (i.e. argv[1]). After the parent has finished computing, it should wait on the first and second child processes to complete before continuing. After each child has finished computing its assigned fibonacci number, it's timer profile should be printed. The parent's profile should be printed after it has done waiting on the children. Your program should be called Fibonacci_timers.c. Following is an example of how such a program should work. $ ./fibonacci_timers 43 44 45 [Child 1] fibonacci (44) = 701408733 Wall Time Spent Executing : 42 seconds, 440000 microseconds Total Time Spent on CPU : 15 seconds, 290000 microseconds Time Spent in User-Space : 15 seconds, 280000 microseconds Time Spent in Kernel-Space: 0 seconds, 10000 microseconds (Child 2] fibonacci (45) = 1134903170 Wall Time Spent Executing : 52 seconds, 310000 microseconds Total Time Spent on CPU : 24 seconds, 310000 microseconds Time Spent in User-Space : 24 seconds, 220000 microseconds Time Spent in Kernel-Space: 0 seconds, 90000 microseconds [Parent] fibonacci (43) = 433494437 Wall Time Spent Executing : 52 seconds, 1000000 microseconds Total Time Spent on CPU : 9 seconds, 1000000 microseconds Time Spent in User-Space : 9 seconds, 1000000 microseconds Time Spent in Kernel-Space: 0 seconds, Omicroseconds $Step 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