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
What is the advantage of buffering? Is buffering always effective? Justify your answer with help of an example. I/O buffer: One type of input-output requirement arises from d

Object oriented modelling Object oriented modelling is entirely a new way of thinking about queries. This methodology is all about visualizing the things by using models organ

Define the term- Verification It is a way of preventing errors when data is copied from one medium to another (for instance from paper to disk/CD or from memory to DVD, etc.).

Q. Diffrence between CD-R vs CD RW? A CD-R disc looks same as a CD. Though all pressed CDs are silver, CD-R discs are gold or silver on their label side and a deep cyan or gree

What is the advantage of doubly linked list over singly linked list?       Ans: Benefits of the doubly linked list over singly linked list 1. A doubly linked list can be pas

What is dynamic random access memory Computer memory today comprises mainly of dynamic random access memory (DRAM) chips which have been built into multi-chip modules that are

Message passing is possible the most widely used parallel programming paradigm these days. It is the most portable, natural and efficient scheme for distributed memory systems. It

State The advantages of specifying parameter assignments using defparam are: - This method always has precedence over specifying parameters at the instance of instantiation.

The Simple Object Access Protocol (SOAP) uses XML to describe a protocol for the exchange of information in distributed computing environments. SOAP having of three components: an

TII stands for? Ans. TII stands for Table of incomplete instructions.