Question: IN C lang please! This program will demonstrate your knowledge of usage of exec family of functions to execute shell commands. The parent will fork
IN C lang please!
This program will demonstrate your knowledge of usage of exec family of functions to execute shell commands.
The parent will fork four child process and each child will call one of the exec family of function, and each will execute ls -l, pwd, ps -e, or cal command.
You should not use the same exec function twice, each should be different, but each will execute of the shell commands list above.
The skeleton version of the program is already given here: All you got to do is just fill in the arguments for the exec function.
[srivatss@athena:118]> cat hw_exec.c
//execv requires full path and all arguments should be
// in a null terminated array
#include
#include
#include
int main( int argc, char *argv[] )
{
pid_t pid;
pid = fork(); // creates a new process
if (pid == 0) {
// TASK 1 : call execl to execute pwd
execl( _______ ) ;
}
else {
printf("parent process waiting for execl to complete " );
}
pid = fork(); // creates a new process
if (pid == 0) {
// TASK 2 call execv to execute ls -l
char *args[ ] = { ______ NULL };
execv(________) ;
}
else {
printf("parent process waiting for execv to complete " );
}
pid = fork(); // creates a new process
if (pid == 0) {
// TASK 3 call execlp to execute ps -e
execlp(_______ ) ;
}
else {
printf("parent process waiting for execlp to complete " );
}
pid = fork( ) ; // creates a new process
if ( pid == 0 ) {
// TASK 4 call execve to execute cal
char *myArgv [ ] = { _________ };
char *myEnv[] = { "HOME=/usr/bin", NULL} ;
execve(___________, _________, myEnv) ;
}
else {
printf("parent process waiting for execve complete " );
}
}
PLEASE ATTACH THE OUTPUT OF THE PROGRAM!
THANKS!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
