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
By 2 pointers you can find it. One of them goes 2 nodes each time. The second one goes at 1 node each time. If there is a cycle, the one that goes 2 nodes every time will eventuall

Q. What are intelligent agents? What tasks will they perform? ANSWER: Intelligent agents are software that helps you, or operate on your behalf, in performing repetitive comput


DUPLICATING PROCESSES : As we mentioned earlier duplicating is a process whereby a master copy is prepared from which a large number of other copies are obtained with the help of

Data is to be transmitted using a modem at 9600 bps. Determine the minimum bandwidth of the system with the following modulation methods (a) FSK (b) ASK. Use the excess bandwidth f

What is the purpose of DOTNET? Dot Net Is a collection of products like C#, ASp.Net, Vb.Net, XML. The purpose of .Net is that we can simply upgrade and degrade our programs whi

What are the advantages and disadvantages of macro pre-processor? Advantages Any of existing conventional assembler can be improved in this way to incorporate macro proces

What is the use of isolated I/O configuration.  In isolated I/O configuration the CPU has distinct input and output instructions and each of these instructions is associated wi

what is fresnel''s biprism?how it is used to determine wavelength of monochromatic source of light

Purpose: Front line client service. Make bookings for vehicle servicing, accesses client database, prints invoices for clients etc. The mechanics complete worksheets for the variou