Question

In: Computer Science

explain the use of fork, exec, and wait functions in unix

explain the use of fork, exec, and wait functions in unix

Solutions

Expert Solution

In this article, can|we'll|we are going to} start from alittle clarification of method IDs so we'll quickly get on to the sensible aspects where-in we have a tendency to will discuss some method connected C functions like fork(), execv() and wait() .

The fork() Function

As already discussed in the article making a daemon method in C, the fork function is used to form a method from inside a method.

The resultant new method created by fork() is best-known as kid method whereas the initial method (from that fork() was called) becomes the parent process.

The function fork() is referred to as once (in the parent process) however it returns double. Once it returns within the parent method whereas the second time it returns in the kid process. Note that the order of execution of the parent and the child might vary relying upon the method programming rule. So we have a tendency to see that fork perform is used in method creation.

The signature of fork() is :

pid_t fork(void);

Another set of functions that are typically used for making a method is the EXEC family of functions. These functions are in the main used wherever there is a demand of running Associate in Nursing existing binary from withing a method.

For example, suppose we wish to run the ‘whoami’ command from inside a method, then in these kind of scenarios the exec() perform or alternative members of this family is employed. A point price noting here is that with a decision to any of the EXEC family of functions, the current method image is replaced by a brand new process image.

A common member of this family is that the execv() function. Its signature is :

int execv(const char *path, char *const argv[]);

There are bound things wherever once a kid method terminates or amendments state then the parent method ought to return to grasp concerning the change of the state or termination standing of the kid method. In that case functions like wait() are employed by the parent method wherever the parent will question the amendment in state of the kid method victimization these functions.

The signature of wait() is :

pid_t wait(int *status);


Related Solutions

Explain how the interrupt mechanism works in Unix? Use a clear and concise diagram.
Explain how the interrupt mechanism works in Unix? Use a clear and concise diagram.
Explain five differences between a fork and thread
Explain five differences between a fork and thread
explain the process of Dna replication fork, transcription, translation
explain the process of Dna replication fork, transcription, translation
explain the functions and use of alternative method for resolving dispute
explain the functions and use of alternative method for resolving dispute
Use the three functions of money to explain why credit cards are not a part of...
Use the three functions of money to explain why credit cards are not a part of the money supply. Answer in your own words.
11. A fork() function call is a system call. true or false 12. A fork() function...
11. A fork() function call is a system call. true or false 12. A fork() function call in a user program is executed in user mode, not in kernel mode. true or false 13. Alice writes a high-level program using some programming language on her home desktop computer and using compilation it transforms into an executable file. Bob's home desktop computer will not execute Alice's executable file. What language was Alice's program written with? 14. Alice rewrites her high-level program...
Basic Unix Commands Objective: The objective of this lab is to work with files of UNIX...
Basic Unix Commands Objective: The objective of this lab is to work with files of UNIX file system. Procedure: 1. OpenyourUnixshellandtrythesecommands: Ø Create a new file and add some text in it vcat > filename Ø View a file vcat /etc/passwd vmore /etc/passwd vmore filename Ø Copy file, making file2 vcp file1 file2 Ø Move/rename file1 as file2 vmv file1 file2 Ø Delete file1 as file2 vrm file //Deletefile //Double-checkfirst vrm -i file Ø Counts the lines, words, characters in...
please use linux or unix to complete, and include pictures of the output. Modify the code...
please use linux or unix to complete, and include pictures of the output. Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will sum up numbers from 801 - 1000 Make main thread wait for other threads to finish execution and sum up all the results. Display the total to the...
List and briefly describe some common functions(features) found in UNIX e-mail systems. i.e. capability of using...
List and briefly describe some common functions(features) found in UNIX e-mail systems. i.e. capability of using Bcc, etc..
You have a tuning fork, called tuning fork A of unknown frequency. you know that when...
You have a tuning fork, called tuning fork A of unknown frequency. you know that when it vibrates, it has a maximum amplitude of 0.002ft. Tuning fork B, which has a period of 0.05s causes tuning for A to vibrate with an amplitude of 0.01ft. Tuning for C which has a period of 0.2s causes tuning fork A to vibrate with an amplitude of 0.015ft. What is the natural frequency of tuning fork A?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT