This is coded on a linux operating system, use system calls whenever possible. I
ID: 3595312 • Letter: T
Question
This is coded on a linux operating system, use system calls whenever possible. I know there is a limit to the questions you can do so only do question 1. Questions 2, 3, and 4 will be posted later
Here is the code for part1.c:
More on Linux Process Management ective To change the executable image of a process and get it to do a totally different job using exec () To investigate what parts of the parent process scope gets inherited and stays with a child process after fork) and/or exec ) system calls Introduce pipes as a communication tool between related processes Description A process is a program in execution. It is the basic unit for running application and performing work in a computer system. An OS creates the data structures it needs to track and manage a process throughout its life cycle (from inception all the way through its termination). To do so, the OS should provide system calls to create a process, change its context so it does something different than its parent, convey status information to its parent and more Linux allows a process to create a new process that is a replica of itself suing the fork() system call The parent process, using the wait )system call, can wait for the newly created child until it finishes its work. The child process can perform a new task by changing its context to a new executable image using a version of exec () A pipe is a Linux kernel object that has a limited buffer and can be used to establish unidirectional communication between processes. It blocks a writer process if the buffer is full and blocks a reader process if the buffer is empty -int pipe(int pipefdI2]) http://man7.org/linux/man-pages/man2/pipe. 2.html -int execl (const char *path, const char *ar -int execlp (const char *file, const char *arg, ..); -int execle (const char *path, const char *arg, .., char const envp] -int execv (const char *path, char const argv[]) -int execvp (const char *file, char const argv[) - int execvpe (const char *file, char *const argv[), char *const envp[) fork(void); pid-t - pid t vfork(void); http://man7.org/linux/man-pages/man2/vfork.2.html - pid t getpid (void) http://man7.ora/linux/man-pages/man2/getpid.2.html - pidt getppid (void) - pid t wait (int *wstatus) http://man7.org/linux/man-pages/man2/waitpid.2.html - pid t waitpid (pid_t pid, int *wstatus, int options); http://na n 7.org/linux/man-pages/ma n 2 / fork.2.html Submission Submit the answers to the questions below in pdf format One compressed file that contains all C and pdf files To get used to system calls please pay attention to the following o o o Check the success of every system call you use Make sure a parent process waits for all its children When using pipes, make sure to close the side the process will not useExplanation / Answer
Answer for part 1 as requested by the student:
1. When a process calls fork(), it clones a child procss from the parent, hence the child process is created duplicatin the parent process. The pointers, variables and memory content will be duplicated for the child processes.Hence C1 and C2 will have its own copy of variables and cannot affect each others memory unless they use memory share.
2. The child processes C1 and C2 will inherit/have access to the file descriptors opened by the parent before forking. The child processes can use the same descriptor and does not require shared memory for this. But it is not advised to use same descriptor when user is trying to write to the file, as buffering in 2 different processes would lead to unexpected results.
3. There is no fixed order of execution between child processes and also between child processes and their parent for that matter. As soon as a process is ready for execution, it may run according to the scheduling config or algorithms.Either of the child jobs or parent process can be scheduled first, there is no rule.
4. Only way to control C1 printing before C2 is by having parent sleep for few seconds, so that C1 can finish its prints before C2 starts its prints.
The only change required is adding a sleep statement
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.