1 / 25

Processes, Signals and Shell Lab

Processes, Signals and Shell Lab. Siddharth Dhulipalla. Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012. Outline. Midterm Overview Processes Signals Shell Lab Overview Cheating Policy Reminder. Midterm Overview. Average: 54/71 Pick up from ECE Course Hub in HH 1112

greta
Télécharger la présentation

Processes, Signals and Shell Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Processes, Signals and Shell Lab • Siddharth Dhulipalla Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012

  2. Outline • Midterm Overview • Processes • Signals • Shell Lab Overview • Cheating Policy Reminder

  3. Midterm Overview • Average: 54/71 • Pick up from ECE Course Hub in HH 1112 • Alternate solution to assembly question found • Regrade requests accepted until Wednesday • Question?

  4. Processes

  5. Processes • What is a process? • An instance of a program in execution • A Great Idea in Computer Science • Ubiquitous on multitasking systems • Fundamental abstraction provided by the OS • Single thread of execution (control flow) • Full, private memory space and registers • Various other state (file descriptors, etc.)

  6. Processes • Four basic process control functions • fork() • exec() • exit() • wait() • Standard on all Unix systems

  7. fork() • Creates a process (more like mitosis than birth) • Parent and child are exactly alike • Except for return value (%eax) • Equal, but private: • Threads of execution • Registers • Memory • File descriptors (note: files, however, are shared)

  8. exec() • Replaces process • No processes created • New process (mostly) unaware of old state • How programs are run • Replace memory image with new program • Set up stack with arguments • Start execution at the entry point (main) • Actually a family of functions • man 3 exec

  9. exec() Example Code int rc = fork(); if (rc == 0) { printf(“child\n”); execl(“/bin/echo”, “/bin/echo”, “sup!”, NULL); exit(EXIT_FAILURE); }printf(“parent\n”); Output child sup! parent Any other possibilities?

  10. exit() • Terminates a process • OS frees resources used by the process • Tiny leftover data • Zombie state • Exit status for parent • Must be freed (reaped)

  11. wait() • Blocks until child process changes state • Reaps child if it terminated • Frees all remaining resources and gets exit status • Can be used for synchronization • Lots of details • man 2 wait

  12. wait() Example Code int rc = fork(); if (rc == 0) { printf(“child\n”); execl(“/bin/echo”, “/bin/echo”, “sup!”, NULL); exit(EXIT_FAILURE); }int status; waitpid(rc, &status, 0); printf(“child status %d\n”, WEXITSTATUS(status)); Output child sup! child status 0 Any other possibilities? Take a look at: http://csapp.cs.cmu.edu/public/waside/waside-graphs.pdf

  13. States • Running • Executing instructions on the CPU • Number bounded by the number of CPU cores • Runnable • Waiting to be running • Blocked • Waiting for an event • Not runnable • Zombie • Terminated but not yet reaped

  14. Signals

  15. Signals • Primitive form of interprocess communication • Notify process of an event • Asynchronous with normal execution • Several types • man 7 signal • Sent in various ways • ^C, ^Z, ^\ • kill command • kill system call

  16. Signals • What to do when receiving a signal • Ignore • Catch and run signal handler • Terminate • man sigaction • Blocking • man sigprocmask • Can’t modify behavior of SIGKILL and SIGSTOP • Signals don’t queue

  17. Signals • Signal Handlers • Can be installed to run when a signal is received • Type is “void (*sa_handler)(int)” • Separate control flow in the same process • Resumes control flow on return • Signal handlers can be called anytime

  18. Signals • Interesting signals • SIGKILL – force kill a process • SIGINT – kill a process • SIGSTOP and SIGCONT – suspend and resume a process • SIGCHLD – child changed state • SIGSEGV – everyone knows this

  19. Shell Lab

  20. Shell Lab • Write a not-so-basic shell • Fork and execute a new program • Wait for foreground jobs • Support background jobs • React to changes in child state • Input and output redirection • ls > ls_out and wc < filename • Many different designs • Some much better than others

  21. Shell Lab Tips • Read the code we’ve given you. • There is a lot of stuff you don’t need to write for yourself. • It’s a good example of the kind of code we expect from you • If you find yourself using sleep() as a way of avoiding race conditions, you are doing it VERY wrong. We will dock performance points for this. • You should only use it for performance to avoid your code having to execute useless instructions. Your code should still work if we remove calls to sleep. • Read the spec carefully and start early!

  22. Shell Lab Hazards • Race Conditions • Hard to debug so start early • Reaping zombies • Again, race conditions • Fiddle with signals • Waiting for foreground job • One of the only places where sleep is acceptable (though you don’t NEED it)

  23. Cheating Policy Reminder • Don’t do it. • Two students caught by Moss have received R’s and could potentially be kicked out of their program • Two more cases are currently looked into • Never worth it.

  24. Questions?

More Related