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
Explain the Reference Count The system relates a reference count along with each memory area to point out the number of its active users. This number is incremented while a us

A Choice is displayed in a compact form that needs you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be shown in

Illustrate the basic structure of the von Neumann machine The following figure shows basic structure of the von Neumann machine. A von Neumann machine has only a single path be

You are being employed as a novice interaction designer on a project to develop a public kiosk providing information about the exhibits available in a science museum. Consider how

Assignment 2: K-nearest neighbor for text classification. The goal of text classification is to identify the topic for a piece of text (news article, web-blog, etc.). Text clas

Q. What is Metropolitan Area Network? Metropolitan Area Network (MAN):  It is privately or public owned communication system that naturally covers a complete city. Speed is abo

Parallelism Conditions As discussed earlier, parallel computing needs the segments to be executed in parallel should be independent of each other. So before executing paralleli

By default, this page is quite barren. Though, go explore the Query Page some more; you will search that you can store numerous queries on the server, so if you regularly run a cer

Typical human voice is centered around                   Hz. (A)  200-400                                     (B)  280-3000  (C)  400-600

Define compilers and interpreters with high level language? Both compilers and interpreters are available for most high-level languages. Though LISP and BASIC are in particular