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
Modular programming denotes to the practice of writing a program as a sequence of independently assembled source files. Every source file is a modular program intended to be assemb

Pascaline:Mechanical computers Blaise Pascal made the initial attempt in the direction of this automatic computing. He invented a apparatus, which comprised of lots of gears an

Q. Programming languages array operations? In programming languages array operations are written in compact form which frequently makes programs more understandable. Conside

First-Order Logic : There's Reasoning, and then There's Reasoning As humans, we have always prided ourselves on our capability to think things by: to reason things out and c

Determine the term - ARTiSAN Software and  BridgePoint ARTiSAN Software : This provides a variety of UML based CASE tools, which also includes a real time modeling tool.

Q. Introduction to the Operating System? An Operating system is software that creates a relation between the User, Hardware and Software. It is an interface between the all.

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. The area under a curve between two points can be foun

In a particular exchange during busy hour 1200 calls were offered to a group of trunks, during this time 6 calls were lost. The average call duration being 3 minutes Calculate Tr

External storage systems A number of different types of external memory devices are available now. Some of these are considered below (hard drives haven't been mentioned as th

Returns the information about tasks running int info = pvm_tasks( int where, int *ntask, struct pvmtaskinfo **taskp ) struct pvmtaskinfo {  int ti_tid; int ti_pt