c programm — 3
Project detail
Write a C program to simulate the following scenario:
1- The parent creates a file, call it “newFile.txt”, and opens an existing file, for example “file.txt”, using the system call open().
2- The parent creates a child using the system call fork().
3- The parent calls the system call wait() to wait for its child process to terminate
4- The child uses the file descriptors, returned to the parent by open(), to read the contents of “file.txt” and write it to the file “newFile.txt”.
5- The child sleeps for 5 seconds, writes the message “Child terminating” to “newFile.txt”, sleeps for another 5 seconds and, finally calls the exit(20
6- The parent, once awake, writes to “Newfile.txt” the message “My child has terminated” and the status value returned by the child.
7- The parent terminates
II.
Write a C program to simulate the following scenario:
1- The parent opens an existing file, for example “file.txt”, using the system call open().
2- The parent creates a child using the system call fork().
3- The parent calls the system call wait() to wait for its child process to terminate.
4- The child uses the file descriptor, returned to the parent by open(), to display on the screen the contents of “file.txt”. This task should be done using the read()/write() system calls.
5- The child sleeps for 5 seconds, prints the message “Child terminating”, sleeps for another 5 seconds and, finally calls the exit(20).
6- The parent, once awake, prints the message “My child has terminated” and print the status value returned by the child.
7- The parent terminates.