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
Problem Show which of the weighted arithmetic mean, geometric mean or harmonic mean, you would use in each of the following case. Justify your answer in each case. (a)

Determine the abstraction mechanisms for modelling The object orientation conceptual structure helps in providing abstraction mechanisms for modelling, that includes: Cl

Representation scheme in artificial intelligence: It is not hard to see why logic has been popular representation scheme inĀ AI: In this way, It is easy to represent knowl

how to implement a modified distribution method using c/c++

Q. What do you mean by Information System? An information system is an planned combination of hardware, people, communication networks, software and data resources that transfo

Q. What is Message Passing Libraries? In this part we will consider about message passing libraries. Traditionally a range of message passing libraries have been available ever

What is meant by branch instruction? A branch instruction is an instruction which changes the contents of the PC with the branch target address. This address is usually get by

Explain the Product of Sum Form - standard forms? The POS is the Boolean Expression containing OR terms, called as sum terms. The product denotes ANDing of these terms. F= (

Q. Show Arithmetic Subtraction? The subtraction can be done easily using 2's complement by taking 2's complement of value which is to be subtracted (inclusive of sign bit) and

With LDB one can change the pre-generated selection screen to their needs Yes with LDB one can alter the pre-generated selection screen.