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
Define race condition.  When several process access and manipulate similar data concurrently, then the outcome of the implementation depends on particular order in which the ac

What is the advantage of wrapping database calls into MTS transactions? Ans) If database calls are made within the context of a transaction, aborting the transaction will undo a

Determine the Example of timescale 'timescale 10ns / 1ps Indicates delays are in 10 nanosecond units with 3 decimal points of precision (1 ps is 1/1000ns which is .001 ns).

Predicates in propositional model: The predicates take a number of arguments in which for now we assume are ground terms and represent a relationship between those arguments t

Name the appliances which are controlled by micro-processor Many household appliances which are microprocessor-controlled do not have operating systems (for example microwave o

Flynn's Classification Flynn's classification is based on multiplicity of data streams and instruction streams observed by the CPU during program execution. Let Ds and Is  are

Two popular encryption techniques to ensute secured transactions on the net? 1. Translation table 2. Word/byte rotation and XOR bit masking.

Q. Learn synchronization principles? To learn synchronization subsequent dependencies are recognized:  i)  Data Dependency: These are RAW, WAW and WAR dependency.  ii) Co

How and what data is collected - Weather simulation -  Sensors measure pressure, relative humidity, temperature and wind speed and wind direction -  Sensors are placed in w

Q. A. Which gates are called Universal Gates? Why? B. State and prove any one of the DeMorgen's Laws. Show that these theorems can be extended up to any number of variables.