Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multi-Part question. Please respond with C code (or C++ just specify) a- Write a

ID: 3888975 • Letter: M

Question

Multi-Part question. Please respond with C code (or C++ just specify)

a- Write a UNIX program that creates a child process

b- Open a file,

Use fprintf() to write 1, 2, 3, … 100 to the file, with each number occupying one line; (Take Screenshot)

Close the file.

c- In a Linux terminal, please run command “ps –ef”. You will see a list of processes in the system.

1. Pick up the bash process (the Shell process) which you are its owner (suppose the process is PROC), obtain its PID (Process ID).

2. go to /proc, then go to the corresponding directory for this process PROC, answer the following question:

What are the cmdline, environ, io, and sched of the process PROC?

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *pointer; //files are accessed through a variable called file pointer
int i;
  
pointer = fopen("num.txt", "w"); //opens a text file named num and "w" stands for "write".

/*For various reasons, the call to fopen() may fail.To make sure the file was opened correctly and if it doesn't, to quit the program*/
if (pointer == NULL) {
printf("Couldn't open num.txt for writing. ");
exit(0);
}

/* write to the file */
for (i=1; i<=100; ++i)
fprintf(pointer, "%d ", i);

/* close the file */
fclose(pointer);

return 0;
}