Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #define MAXLINE 80 /* The maximum length command */ int main(void) { char *args[MAXLINE/2 + 1]; /* command line arguments */ int should_run

#include #include

#define MAXLINE 80 /* The maximum length command */ int main(void) { char *args[MAXLINE/2 + 1]; /* command line arguments */ int should_run = 1; /* flag to determine when to exit program */ char *prog = NULL; char **args = NULL; while (should_run) { printf(mysh); fflush(stdout); /** *After reading user input, the steps are: * (1) fork a child process using fork() * (2) the child process will invoke execvp() */ int child_pid = fork();

if (child_pid == 0) { /* Im the child process, run program with parents I/O exec(prog, args); } else { /* Im the parent: wait for the child to complete wait(child_pid); return 0; } } return 0; }

The above pseudocode illustrates the basic operation of a shell. The shell reads a command line from the input, and it forks a process to execute that command. UNIX fork automatically duplicates all open file descriptors in the parent, incrementing the kernels reference counts for those descriptors, so the input and output of the child is the same as the parent. The parent waits for the child to finish before it reads the next command to execute. Because the commands to read and write to an open file descriptor are the same whether the file descriptor represents a keyboard, screen, file, device, or pipe, UNIX programs do not need to be aware of where their input is coming from, or where their output is going. This is helpful in a number of ways: A program can be a file of commands.

A program can send its output to a file.

A program can read its input from a file.

The output of one program can be the input to another program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

1-13. What is a disruptive innovation?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago