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

Explain input - output techniques, Q. Explain the Hard Disk Controller & F...

Q. Explain the Hard Disk Controller & Floppy Disk Controller with necessary diagrams. Q. Explain Input/Output Techniques (Data Transfer Techniques).

Describe the errors, Q. Describe the Errors? Errors  Two probable...

Q. Describe the Errors? Errors  Two probabletypes of errors may take place in assembly programs:   a. Programming errors: They are familiar errors you may encounter in

How a typical dma controller can be interfaced to an 8086, Demonstrate how ...

Demonstrate how a typical DMA controller can be interfaced to an 8086/8085 based maximum mode system.  For 8088 in maximum mode: The RQ/GT0 and RQ/GT1 pins are used to is

Hard disk architecture, Hard disk Architecture: A hard disk drive ...

Hard disk Architecture: A hard disk drive having the platters and motor hub removed indicating the copper colored stator coils surrounding a bearing at the cen

Computer graphics, list out of merit and de-merit plasma display

list out of merit and de-merit plasma display

How numbering plan is achieved in modern telephony, How numbering plan is a...

How numbering plan is achieved in modern telephony? Give the structure with example. The objective of numbering plan is to uniquely identify every subscriber connected to a tel

Find the minimum sop and pos expression, Find the minimum SOP and POS expre...

Find the minimum SOP and POS expression for the following functions using Karnaugh Map and realize the expression using appropriate gates. Also realize SOP form using NAND-to-NAND

Can we use write statements in screen fields, Can we use WRITE statements i...

Can we use WRITE statements in screen fields? If not how is data transferred from field data to screen fields? We cannot write field data to the screen using the WRITE stateme

What is the benefit of report wizard over an auto report, What is the benef...

What is the benefit of Report Wizard over an Auto Report? It takes a little more work to make a report with the report wizard than with the Auto Report but you have a lot more

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