Question: please do this in C Write a function fib(int n) in lab2.c that will return the nth term for the Fibonacci sequence. A Fibonacci sequence

please do this in C please do this in C Write a function fib(int n) in lab2.c

Write a function fib(int n) in lab2.c that will return the nth term for the Fibonacci sequence. A Fibonacci sequence has no oth term. It starts with the 1st term. 1. In main immediately read the first command line argument past the filename. Call atoi to convert the argument into an integer n, which you will pass later as an argument for fib and use as the child's exit code. If no arg is passed, exit with code 1, and write this usage statement to stdout: "Usage: lab2 n" 2. After grabbing the cmd-line arg, call fork to fork a child process. 3. The child calls open (2) to open a file for writing named 'log'. 4. The child calls write(2) to write date and result of fib(n) to log. 5. The child calls close(2) to close log. 6. The child exits and passes n as the exit code. 7. After the fork, the parent immediately calls wait. 8. After wait returns the parent calls write to display the child's exit code to stdout (see fork3.c) 9. the parent terminates with exit code e. Sample run: $ gcc lab2.c -ansi -pedantic -Walt olab2 $ strace -q -f -e trace=write /labe 15 per my child exited with code: 15 $ cat log 2015:03:23 22:34:51 fib 15 = 610 $ cat err [pid 23517] write(3, "2015:03:24 0932:28 ", 20) = 20 [pid 23517) write(3, "fib 15 = 6101, 13) = 13 SIGCHLD (Child exited) @@ () write(1, "my child exited with code 151n", 30) = 30 $ ./lab2 Usage: lab2 n $ echo $? 1

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!