Lecture12-intro-to-processes-part4

Lecture12-intro-to-processes-part4 - Announcements CS 3214...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS 3214 Computer Systems Godmar Back Lecture 12 Announcements • Exercise 4 due Sep 30 • Project 3 due Oct 14 • Please read FAQ – Hid two samples of code you can use to simplify your job CS 3214 Fall 2011 THREADS AND PROCESSES Part 4 CS 3214 Fall 2011 esh – extensible shell • Open-ended assignment • Encourage collaborative learning – Run each other’s plug-ins • Does not mean collaboration on your implementation • Secondary goals: – Exposure to yacc/lex and exposure to OO- style programming in C CS 3214 Fall 2011 Using the list implementation struct esh_pipeline: …. struct list commands struct list_elem head struct list_elem *next; struct list elem *prev; struct esh_command: …. struct list_elem elem; …. struct list_elem *next; struct list_elem *prev; struct esh_command: …. struct list_elem elem; …. struct list_elem *next; struct list_elem *prev; list_entry(e, struct esh_command, elem) • Key features: “list cell” – here call ‘list_elem’ is embedded in each object being kept in list – Means you need 1 list_elem per list you want to keep an object in CS 3214 Fall 2011 struct list_elem tail _ struct list_elem *next; struct list_elem *prev; Unix Startup: Step 1 1. Pushing reset button loads the PC with the address of a small bootstrap program. 2. Bootstrap program loads the boot block (disk block 0). 3. Boot block program loads kernel binary (e.g., /boot/vmlinux ) 4. Boot block program passes control to kernel. 5. Kernel handcrafts the data structures for process 0. init [1] [0] Process 0: handcrafted kernel process Child process 1 execs /sbin/init Process 0 forks child process 1 CS 3214 Fall 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Unix Startup: Step 2 init [1] [0] /etc/inittab init forks and execs daemons per getty Daemons e.g. sshd, httpd /etc/inittab , and forks and execs a getty program for the console CS 3214 Fall 2011 Unix Startup: Step 3 init [1] [0] The getty process execs a login program login CS 3214 Fall 2011 Unix Startup: Step 4 init [1] [0] login reads login and passwd reads login and passwd. if OK, it execs a shell. if not OK, it execs another getty tcsh CS 3214 Fall 2011 Shell Programs •A shell is an application program that runs programs on behalf of the user. –s h – Original Unix Bourne Shell – csh – BSD Unix C Shell, tcsh – Enhanced C Shell – bash – Bourne-Again Shell Execution is a sequence int main() { char cmdline[MAXLINE]; while (1) { Execution is a sequence of read/evaluate steps /* read */ printf("> "); fgets(cmdline, MAXLINE, stdin); if (feof(stdin)) exit(0); /* evaluate */ eval(cmdline); } } CS 3214 Fall 2011 void eval(char *cmdline) { char *argv[MAXARGS]; /* argv for execve() */ int bg; /* should the job run in bg or fg? */ pid_t pid; /* process id */ bg = parseline(cmdline, argv); if (!builtin_command(argv)) { if ((pid = fork() ) == 0) { /* child runs user job */ if ( execve (argv[0], argv, environ) < 0) { printf("%s: Command not found.\n", argv[0]); exit (0); } } if (!bg) { /* parent waits for fg job to terminate */ int status; if ( waitpid (pid, &status, 0) < 0) unix_error("waitfg: waitpid error"); } else /* otherwise, don’t wait for bg job */ printf("%d %s", pid, cmdline); } } Simple Shell eval Function CS 3214 Fall 2011 Problem with Simple Shell Example • Shell correctly waits for and reaps foreground jobs.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Lecture12-intro-to-processes-part4 - Announcements CS 3214...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online