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

Differentiate between absolute and relative poverty, Question 1: Using ...

Question 1: Using appropriate diagrams, describe the optimal provision of a private good and a public good. Question 2: Using appropriate diagram, show how there is an

What are threads, What are threads? A thread, sometimes termed as a lig...

What are threads? A thread, sometimes termed as a lightweight process (LWP), is a fundamental unit of CPU utilization; this comprises a thread ID a register set and a stack and

Assignment, zero, one, two three address instructions

zero, one, two three address instructions

Categorized the optimization transformations, Categorized Optimization tr...

Categorized Optimization transformations The structure of program and the way in that data is defined and used in this provide vital clues for optimization. Optimization t

List the steps needed to perform page replacement, List the steps needed to...

List the steps needed to perform page replacement. The steps required to perform page replacement are: 1. Find out which page is to be removed from the memory. 2. Perfor

Illustrate about compact disk rewritable, Q. Illustrate about Compact Disk ...

Q. Illustrate about Compact Disk Rewritable? CD-RW optical disk can be repeatedly written and overwritten same as with a magnetic disk. Even though a number of techniques have

Simplify the expressions using boolean postulates, Simplify the given expre...

Simplify the given expressions using Boolean postulates XY + X‾Z‾  + XY‾Z (XY + Z) Ans. XY + X‾Z‾ + XY‾Z (XY + Z) = XY + X‾Z‾ + XY‾Z (XY + Z) = XY + X‾Z‾  + XXYY‾Z

Which address is specially used by transport layer, The addressing speciall...

The addressing specially used by Transport Layer is? The addressing particularly used through transport layer is application port address.

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

What is semaphores, What is semaphores?  A semaphore 'S' is a synchroni...

What is semaphores?  A semaphore 'S' is a synchronization tool which is an integer value that, apart from initialization, is accessed only by two standard atomic operations; wa

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