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
Signify this problem by means of: i.    An Entity Relationship model; ii.    Relational tables. Pete's Programmers is a firm which supplies part time staff on contract to organisat

Determine the registers are available in machines Typical registers, some of which are commonly available in machines. These registers are as follows:- Memory Addres

DLQ - Dead Letter Queue If an application tries to put a message to one more application and if it is not delivered then it goes to the DLQ. So DLQ is not anything but all und

Device drivers are special programs installed by config.sys file to control installable devices.  So personal computers can be expanded at some future time by installation of new d

create a BCD adder combinational ckt. that adds 2 digit BCD inputs

Define the term- encryption The user would then type in O P E and card purchase will be authorised. This extra protection is used as well as encryption. Some of the new syste

Explain the Register transfer language Register transfer language means there must be data flow between two registers and logic is in between them for end registers data must f

What is the difference between top-down and bottom-up, programming? Ans: Top-down and Bottom-up Approaches In Top-down programming approach, we begin by identifying the main

The Internet has emerged as a major worldwide distribution channel for goods, managerial, services, and professional jobs. It has impacted market economics and industry structure,

What is a disk drive? The electro mechanical mechanism that spins the disk and moves the read/write heads known as disk drive.