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
Why WAP gateways are used? The Wireless Application Protocol Gateway is a very unique product giving semi -automatic redirection of HTML documents to WAP compatible mobile phon

Explain architecture of World Wide Web with the basic entities. The architecture of the World Wide Web, demonstrated below, is the one of clients, as like Netscape, Lynx or Int

Bitwise-Exclusive-OR Operator: ^ exclusive-OR-expression : AND-expression exclusive-OR-expression ^ AND-expression The  bitwise-exclusive-OR  operator  (^)  compares

What is Public Key Cryptography Public-key cryptography is a form of modern cryptography which permits users to communicate safely without lastly agreeing on a shared secret

What is the difference between data warehousing and data mining? The dissimilarity between data warehousing and data mining: Data warehousing seems to the data storage wh

In the organisation of an associative memory, many registers are used: Comparand Register (C): This register is used to grasp the operands, which are being searched for, or

Q. What is Video Card Interfaces? A video interface is the link of video system to rest of the PC. To improve video performance there is required to be an intimate connection betw

Assembly directives and pseudo-ops: Assembly directives are which instructions that executed by the assembler at assembly time, not by the CPU at run time. They can build the

Pass I of the assembler must also generate the intermediate code for the processed statements. Justify your answer. Criteria for selection of a suitable intermediate code form

Describe the purpose and operation of Register 2 (R2) for the MSP430