Execute the command in linux, Computer Engineering

Assignment Help:

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.


Related Discussions:- Execute the command in linux

How music is produced and generated - cad, How music is produced and genera...

How music is produced and generated - CAD Computer software and hardware advances have changed how music is produced and generated. Some of the primary reasons for this have

Concept of pipelining, Describe the concept of pipelining. Ans: Pipeli...

Describe the concept of pipelining. Ans: Pipelining is the means of executing machine instructions concurrently. This is the effective way of organizing concurrent activity in

Equivalence between vhdl and c, Equivalence between VHDL and C? There i...

Equivalence between VHDL and C? There is concept of understanding in C there is structure.Based upon requirement structure provide facility to store collection of various data

What are conditional chain statement, What are conditional chain statement?...

What are conditional chain statement? ON CHAIN-INPUT similar to ON INPUT. The ABAP/4 module is called if any one of the fields in the chain having a value other than its in

Data type, Define data type and abstract data type comment upon the signifi...

Define data type and abstract data type comment upon the significant of both

Generic techniques developed - artificial intelligence, Generic Techniques ...

Generic Techniques Developed: In the pursuit of solutions to various problems in the above categories, various individual fundamental techniques have sprung up which have been

What is a javabean, JavaBeans are reusable software components written in t...

JavaBeans are reusable software components written in the Java programming language, designed to be influenced visually by a software development environment, like JBuilder or Visu

How many types of stages include in process of data mining, How many types ...

How many types of stages include in process of data mining? The process of data mining comprised three stages as given below: a) The initial exploration b) Model buildin

What are the two ways in which the system using cache, What are the two way...

What are the two ways in which the system using cache can proceed for a write operation? Write by protocol technique Write-back or Copy-back protocol method

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd