Presentation is loading. Please wait.

Presentation is loading. Please wait.

4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission.

Similar presentations


Presentation on theme: "4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission."— Presentation transcript:

1 4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission

2 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Goals Understand how a simple shell works. Understand systems calls, such as fork, read, wait, execvp, and etc. Understand signal handling mechanisms

3 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Descriptions Demo command> ls commnad> cat proj1.c command> ctr-c command> ctr-d Input: commands from keyboard Fork a child process to perform the command Store the past commands in a buffer Given a signal, display the most recent commands in the buffer Ctrl-C terminates the shell

4 4.4 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Methodology How to get the command from the keyboard? Use system call read() with STDIN_FILENO Implement a setup() void setup(char inputBuffer[], char *args[], int *background) setup() reads in the next command line, separating it into distinct tokens using whitespace as delimiters. setup() sets the args parameter as a null-terminated string. Also set background =1 if & is met If “ctrl-d” is met, just simply call exit(0);

5 4.5 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Methodology How to execute the command? while (1){ /* Program terminates normally inside setup */ background = 0; printf(" COMMAND->\n"); setup(inputBuffer,args,&background); /* get next command */ /* the steps are: (1) fork a child process using fork() (2) the child process will invoke execvp() (3) if background == 1, the parent will wait, otherwise returns to the setup() function. */ }

6 4.6 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Methodology How to display recent commands? Use signal handler: CTRL-C is the SIGINT signal /* the signal handler function */ void handle_SIGINT() { write(STDOUT_FILENO,buffer,strlen(buffer)); exit(0); } int main(int argc, char *argv[]) { /* set up the signal handler */ struct sigaction handler; handler.sa_handler = handle_SIGINT; sigaction(SIGINT, &handler, NULL); strcpy(buffer,"Caught \n"); /* wait for */ while (1); return 0; }

7 4.7 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Methodology How to keep track of past commands? Limited-size buffer, why not use circular buffer? Modify setup() to store the current command which may overwrite the oldest command in the buffer Implement SININT signal handler to display the 10 most recent commands

8 4.8 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Suggested Steps Step 1: implement setup() Step 2: execute the command from setup() Step 3: add the history feature

9 4.9 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Submission Email to zhuy@seattleu.eduzhuy@seattleu.edu All source files A readme file that describes each file, how to compile the file(s), and how to run the file. If there is any problem running the file, please state it here as well. Makefile may be a good option Due: 10/10/2006, Tuesday 1:30PM

10 4.10 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Questions


Download ppt "4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission."

Similar presentations


Ads by Google