Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this homework, you are to gain some familiarity with the process management APIs about which you just read. Don't worry - it's even more
In this homework, you are to gain some familiarity with the process management APIs about which you just read. Don't worry - it's even more fun than it sounds! You'll in general be much better off if you find as much time as you can to write some code, so why not start now? Questions 1. Write a program that calls fork (). Before calling fork (), have the main process access a variable (e.g., x) and set its value to some- thing (e.g., 100). What value is the variable in the child process? What happens to the variable when both the child and parent change the value of x? 2. Write a program that opens a file (with the open() system call) and then calls fork () to create a new process. Can both the child and parent access the file descriptor returned by open()? What happens when they are writing to the file concurrently, i.e., at the same time? 3. Write another program using fork(). The child process should print hello; the parent process should print "goodbye". You should try to ensure that the child process always prints first; can you do this without calling wait() in the parent? 4. Write a program that calls fork () and then calls some form of exec() to run the program /bin/ls. See if you can try all of the variants of exec(), including (on Linux) execl(), execle(), execlp(), execv(), execvp (), and execvpe (). Why do you think there are so many variants of the same basic call? 5. Now write a program that uses wait() to wait for the child process to finish in the parent. What does wait() return? What happens if you use wait () in the child
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started