Question: Using the codes below explain what the code does and the system calls that make it happen. Also describe the different stages of the program

Using the codes below explain what the code does and the system calls that make it happen. Also describe the different stages of the program as seen in the system call trace.

Write a program in C to demonstrate the working of Fork and Exec

Demonstrate how do pipes enable IPC

--------------------------------------------------------------------------------------------

opeFile-2.c

#include

#include

#include

extern int errno;

int main()

{

// if file does not have in directory

// then file foo.txt is created.

int fd = open("foo.txt", O_RDONLY | O_CREAT);

printf("fd = %d/n", fd);

if (fd ==-1)

{

// print which type of error have in a code

printf("Error Number % d ", errno);

// print program detail "Success or failure"

perror("Program");

}

return 0;

}

openFile.c

#include

main() {

FILE *fp;

fp = fopen("./test.txt", "w+");

fprintf(fp, "This is testing for fprintf... ");

fputs("This is testing for fputs... ", fp);

fclose(fp);

}

openFileAndInp.c

#include

main() {

FILE *fp;

char buff[255];

fp = fopen("/tmp/test.txt", "r");

fscanf(fp, "%s", buff);

printf("1 : %s ", buff );

fgets(buff, 255, (FILE*)fp);

printf("2: %s ", buff );

fgets(buff, 255, (FILE*)fp);

printf("3: %s ", buff );

fclose(fp);

}

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!