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
With respect to security, which one is the better choice?.Net or J2EE? Explain? As per majority programmers .NET is the best one which have one vendor compare to, the ease of

Program: A good illustration of code conversion: Write a program to convert a; 4-digit BCD number into its binary equivalent. BCD number is stored as a; word in memory location kno


write a program to find the area under the curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits of a and b

Explain the following the address instruction?  Three-address instruction-it can be represented as add a,b,c Two-address instruction-it can be shown as Add a,b

Example of Prolog: We can say that this is also true if there are four even numbers. Now we have our first rule: • If there are three or four even numbered cards, such play

Define interrupt. An interrupt is any exceptional event that causes a CPUU to temporarily transfer control from its present program to another program , an interrupt handler th

What is use case and use case diagram? A use case is a coherent piece of functionality that a system can give by interacting with actors. Use case includes one or more actors a

What are disadvantages of the asynchronous reset and synchronous reset? Disadvantages of asynchronous reset: Make sure that the release of the reset can arise within one c

Sigmoid units - Artificial intelligence Remember that the function inside units take as input the weighted sum, S, of the values coming from the units associated to it. The fun