Write a C program called myshell.c, which, when compiled and run, will do what the shell does, namely,
It executes in a loop (until user types exit on the keyboard), prints a prompt on the screen, reads the command typed on the keyboard (terminated by \n), creates a new process and lets the child execute the user’s command, waits for the child to terminate and then goes back to beginning of the loop.
If the command typed is exit, then your program should terminate.
Print the total number of commands executed just before terminating your program.
Assume that each line represents one command only, no command will end with & (all commands will be attached commands, no background execution),
User will not type ^c or ^z, all commands are simple commands, etc.
Useful system calls: fork(), exec() and its several variations, wait().

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>

#define MAX_LEN 1024

* split string to array of smaller string separated by spaces
* @param command
* @return array of pointers
char ** split(char * command);

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

    int i;
    char * input;
    int flag = 0;
    size_t len;
    int size;
    int child_status;
    char ** arg;
    int counter;
    pid_t child_pid;
    char * tmp;

    input = (char *) calloc(MAX_LEN, sizeof (char));
    counter = 0;
    printf("myshell is running\n");...

By purchasing this solution you'll be able to access the following files:

50% discount

$45.00 $22.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Operating Systems Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats