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
WestEast College hires you as a systems analyst to design its new admission/registration system. WestEast College is one of the top ranked schools in the United States. It is a

Let us review the operation of the stack within the 68HC11, the stack is a defined area of RAM which is last in first out register (LIFO) . Access to the stack is made via a stack

What is XMS Memory system is divided into 3 main parts. TPA (transient program area), system area and XMS (extended memory system). Type of microprocessor in your computer sign

Q. Illustrate Diffrent types of modems? There are four different types of modems: half-duplex, full-duplex, synchronous, and asynchronous.With half-duplex modems data can be tr

1) Define a job scheduling strategy that will meet business requirement of reporting availability by 6am CST for the following cubes? Show the job scheduling dependencies in a pict

Q.  Develop a Menu driven program with following menu: 1.  Octal to Decimal 2.  Octal to Hexadecimal 3.  Octal to Binary

Question: (a) Explain clearly the difference between J-cuts and L-Cuts. (b) What is the function of the rate stretch tool? (c) What's the difference between an Image Matt

The performance instrumentation states on how to efficiently gather information about the computation of the parallel computer. The process of instrumentation mainly attempts to ca

When web pages containing emails are sent out they are prefixed by MIME Header. Why? Primarily email consisted messages having simple text written into English and expressed in