Execute the command in linux, Computer Engineering

Now that the user's command has been parsed into an array of char*, we can pass this to the OS to execute the command. To execute the command, use the execvp() function from unistd.h. You will pass your command array to this function which will execute the command. Remember that if this function executes properly, it will terminate the current process; so, it should be executed in a child process. The child process can be created with the fork() function which is also in unistd.h. While the child process is executing the command, the parent process should wait for the child to finish executing. This is done by using the waitpid() function which can be found in sys/wait.h. As you are waiting on the child process, you will want to make this call blocking. You can do this by giving the WUNTRACED option to the waitpid() call which is defined in sys/types.h. Remember that if the execvp() function does not complete successfully, the child process will not end. As this will only happen when an error occurs, this would be a good place to print the error message. This can be done easily by calling the perror(NULL) function. Then be sure to end the child process by calling the exit() function. Once the command is done, you should print your prompt on a new line.

Posted Date: 4/3/2013 2:55:58 AM | Location : United States







Related Discussions:- Execute the command in linux, Assignment Help, Ask Question on Execute the command in linux, Get Answer, Expert's Help, Execute the command in linux Discussions

Write discussion on Execute the command in linux
Your posts are moderated
Related Questions
Add -20 to +26 by using 2's complement ? Ans. Firstly convert the both numbers 20 and 26 in its 8-bit binary equivalent and determine the 2's complement of 20, after that add -

1.Local queue -is a actual queue 2.Cluster queue -is a local queue that is called as throughout a cluster of queue managers 3. Remote queue -structure explaining a queue

What are disadvantages of EPROM? The chip must be physically removed from the circuit for reprogramming and its whole contents are erased by the UV light.

Describe the concept of pipelining. Ans: Pipelining is the means of executing machine instructions concurrently. This is the effective way of organizing concurrent activity in

(a) Why did SAP introduce the extended star schema? Explain why it is reported to be better than the traditional schema model? (b) What is the difference between a dimension use

127.0.0.1 is a? 127.0.0.1 it is a loop-back address.

What is meant by stacked list? A stacked list is nothing but secondary list and is showed on a full-size screen unless you have specified its coordinates using the window comm

Which is the best programming language to learn?

Explain the different sub-functions of Process Scheduling. Process scheduling contains the subsequent sub-functions: 1. Scheduling: Chooses the process to be executed next

Five popular hashing functions are as follows:- Division Method Midsquare Method Folding Method Multiplicative method Digit Analysis