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
Q. What is Keyboard Layout? A keyboard layout is arrangement of keys across the keyboard. There is one keyboard layout which anybody who has worked on a standard keyboard or ty

Utility Functions - artificial intelligence: A goal based on an agent for playing chess is infeasible: at every moment it decides which move to play next, it sees whether that

What is SCSI? Ans: It is the acronym for small computer system interface. It refers to a standard bus explained ANSI. Devices such as disks are linked to a computer via 50-wire

Can I get the scheduling code for NachOS?

Memory Organization - Computer architecture: BASIC CONCEPTS: Address space - 16-bit : 216 = 64K mem. locations - 32-bit : 232 = 4G mem. locations -          40-b

Q. Analysis of Amdahls law? The conclusions of analysis of Amdahl's law are: 1) To optimize performance of parallel computers modified compilers should be developed that sho

Explain Remote Procedure Call. RPC (Remote Procedure Call) : The facility which was created to help the programmers write client -server software is termed as Remote Procedu

Multiple Instruction and Single Data stream (MISD): In this type of organization multiple processing elements are ordered under the control of multiple control units. Every contro

Implicative normal form: Thus the sentence is now in CNF. In Fact for simplification can take place by removing duplicate literals and dropping any clause that contains both A

Q. Explain about Transmission Media? These, also known as physical channels, can be either bounded or unbounded. Bounded media, in which signals representing data are confined