PROGRAM DESCRIPTION: Write two C programs that demonstrate the use of fork() and execv(). PROGRAM REQUIREMENTS: A file c
Posted: Sun Jul 10, 2022 11:26 am
PROGRAM DESCRIPTION: Write two C programs that demonstrate theuse of fork() and execv(). PROGRAM REQUIREMENTS: A file calledsum.c that does the following: • Declare an integer array that canhold up to 10 integer values. • In a for loop, initialize theinteger array with the first 10 natural numbers (excluding 0).Integer 1 at index 0, integer 2 at index 1 and so forth. • In asecond for loop, compute the cumulative sum of the first 10 naturalnumbers and store it in a variable called sum. • Display a messagewith the sum of the first 10 natural numbers using printf. •Compile the program and rename the executable as sum. A file calledsum_fork.c that does the following: • Fork a child process usingfork () and store the return value in a variable named pid. • Usingexecv(), ensure that the child process executes the previouslycreated binary, sum. • Also within the child process, print the PIDof the process executing instructions using getpid(). • Outside ofthe child process section, ensure that the parent process waits forthe completion of the child process using wait() and print the PIDof the process executing instructions using getpid(). EXPECTEDOUTPUT: $ ./a.out The sum of the first 10 integers is 55