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

What is the difference between a structure and a table, What is the differe...

What is the difference between a structure and a table? Structures are constructed the almost the similar way as tables, the only dissimilarity using that no database table is

What do you mean by numbering and addressing, What do you mean by numbering...

What do you mean by numbering and addressing? Numbering and Addressing: In data networks and telephone, the end equipments are more frequently single units than multiple dev

What do you mean by proc directive, Q. What do you mean by PROC Directive? ...

Q. What do you mean by PROC Directive? PROC Directive: Code segment comprises executable code for a program that includes one or more procedures defined initially with PROC dir

Explain macro definition and call, Explain Macro definition and call. ...

Explain Macro definition and call. Macro: The assembly language programming frequently finds this necessary to repeat certain piece of code several times during the course of

Why array index starts from zero, This boils down to the concept of Binary ...

This boils down to the concept of Binary digits. Take an array size of 64 for example. We begin from 0 and end at 63. We need 6 bits.But, if we were to begin from 1 and end at 64,

What is the impact of overflow for binary numbers, Q. What is the impact of...

Q. What is the impact of overflow for binary numbers? An overflow is said to have happened when sum of two n digits number takes n+ 1 digits. This definition is perfectly appli

Mips simulator: testing, Your code will be tested using a command script. T...

Your code will be tested using a command script. The script is available on Blackboard in the archive MIPSimTest.zip. It contains a ReadMe file that explains how to run the script

How many types memory mgt can divided, They are of two types. They are big ...

They are of two types. They are big endian and little endian. Memory is separated into two bank, 1:even bank 2:odd bank.

Explain the virtual memory, What is virtual memory?  Virtual memory is ...

What is virtual memory?  Virtual memory is a technique that permits the execution of processes that may not be completely in memory. It is the separation of user logical memory

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