Are file descriptors of a parent inherited by child process

Assignment Help Computer Engineering
Reference no: EM132094010

Please answer the following questions based on the C code for Program1A.c and Program1B.c

1. Are any of the variables of a parent shared with any of its child processes? Do the children of the same parent share some variables between themselves?

2. Are file descriptors of a parent inherited by child processes? Specifically, if a file Project1.txt is opened by a parent and kept open across a call to fork, is Project1.txt still open in the child process? If the answer is yes, when a child process reads blocks from Project1.txt, will the parent remain at the same position in Project1.txt?

3. Remember that the wait and exit calls can be used for communication between a parent process and its child processes. Now modify Project1A.c so that the parent process terminates only after BOTH its child processes have terminated.

4. Is it allowed for a parent to terminate before one of its child processes has terminated? If so, does this affect the child processes in any way?

Is it possible for the parent process in Project1A.c to terminate one of its child processes, say A1 or A2? Now, is it possible for the parent process in Project1B.c to terminate one of its grandchild processes, say A1 or A2? If so, how? Hint: Using exit to pass data between the child and parent will not work in this case. For details, see the man page for wait.

Project1A.c

#include
#include

int main()
{
pid_t pid1, pid2;
pid1 = fork();
if (pid1 == 0) { // child process
printf("Child process A1 created\n");
}
else {
pid2 = fork();
if (pid2 == 0) { // 2nd child process
printf("Child process A2 created\n");
} else{
waitpid(pid2,0,0); // wait till child process ends
waitpid(pid1,0,0); // wait till child process ends
}
}
return 0;
}

Project1B.c

#include
#include


int main()
{
pid_t pid1;
pid1 = fork();
if (pid1 == 0) { // child process
execv("Project1A",NULL); // run another process named Project1A
exit(127);
} else {
waitpid(pid1,0,0); // wait till child process ends
}

return 0;
}

Reference no: EM132094010

Questions Cloud

Write a program that creates an array of 1000 random numbers : Write a program that creates an array of 1000 random numbers in the range 1 - 5000. Then ask the user for a value between and 5000.
What are the purposes of control flow testing : What are the purposes of Control Flow testing and who needs to conduct Control Flow testing?
Describe such an attack : It is even easier to solve the Hill cipher if a chosen plaintext attack can be mounted. Describe such an attack.
Consider the various training and development formats : Consider the various training and development formats described in chapter 8. Which three do you think would be most effective for developing the skills
Are file descriptors of a parent inherited by child process : Is it allowed for a parent to terminate before one of its child processes has terminated? If so, does this affect the child processes in any way?
Contemporary leadership competencies : You have become comfortable with contemporary leadership competencies and feel it is time to open your own small business. As a future business
Discuss how employers can justify the use of tools : Privacy goes hand in hand with security, but many of the activities of information security analysts seem to be an invasion of privacy.
Expected results of implementing your communication plan : You will need to review the products you created and describe what those products are and how they work together. A conclusion that specifies the expected
Explain what communication-conflict management : Explain what communication/conflict management strategy would be effective to eliminate anger felt by the two directors not chosen?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd