Computer Science, asked by matezu, 11 months ago

Write a program i.e. is a version of a shell that can take command(s) from the user and execute
them on behalf of the user (by spawning a child process to execute the command on behalf of
the parent process). It can only execute a few commands as listed below:
[+] mkdir [ ... ]
[+] ls []
[+] cp
[+] mv [ ... ]
[+] vi
where parameters enclosed in [] are optional parameters.
Note that multiple commands are recognized by the shell if each command is delimited by
";". These commands will be executed one after the other.

The C program that will act as a shell interface which should accept and execute each command in
separate process. There should be a parent process that will read the command and then the parent
process will create a child process that will execute the command. The parent process should wait for the
child process before continuing. Your program should mimic Linux terminal. This program should be
written in C and executed in Linux. You are required to implement five commands out of which one
command should be the editor. The program design is entirely up to you but make sure that your shell
interpreter is easy to modify.

Answers

Answered by aryaveerharsh
0

Answer:

ita linux pita chingus

Answered by mad210219
1

Given:

It can only execute a few commands as listed below:

[+] mkdir [ ... ]

[+] ls []

[+] cp

[+] mv [ ... ]

[+] vi

where parameters enclosed in [] are optional parameters.

Note that multiple commands are recognized by the shell if each command is delimited by

";". These commands will be executed one after the other.

The C program that will act as a shell interface which should accept and execute each command in

separate process. There should be a parent process that will read the command and then the parent

process will create a child process that will execute the command. The parent process should wait for the

child process before continuing. Your program should mimic Linux terminal. This program should be

written in C and executed in Linux. You are required to implement five commands out of which one

command should be the editor. The program design is entirely up to you but make sure that your shell

interpreter is easy to modify.

To find:

A program i.e. is a version of a shell that can take command(s) from the user and execute  them on behalf of the user (by spawning a child process to execute the command on behalf of  the parent process).  

Solution:

#include <unistd.h>

#include <stdlib.h>

#include <stdio.h>

int main(int argc, char * argv[]){

 //argv array for: ls -l

 char * ls_args[] = { "ls" , "-l", NULL};

 //                    ^  

 //  use the name ls

 //  rather than the

 //  path to /bin/ls

 execvp(   ls_args[0],     ls_args);

 //only get here on error

 perror("execv");

 return 2;

}

aviv@saddleback: demo $ ./execvp_ls-l  

total 120

-rwxr-x--- 1 aviv scs  9890 Feb 24 14:13 exec_other

-rw-r----- 1 aviv scs   151 Feb 24 11:43 exec_other.c

-rwxr-x--- 1 aviv scs  9977 Feb 24 14:13 execv_ls-l

Similar questions