1 / 8

Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming

Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming. B. Ramamurthy. Multi-tasking. How to create multiple tasks? Ex: Xinu create() How to control them? ready() resched() How to synchronize them? How to communicate among them?

eshe
Download Presentation

Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming

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. Task Control:Signals and AlarmsHavilland and Salama’s Unix Systems Programming B. Ramamurthy

  2. Multi-tasking • How to create multiple tasks? Ex: Xinu create() • How to control them? • ready() • resched() • How to synchronize them? How to communicate among them? • XINU: semaphores, send and receive messages • How to (software) interrupt a process? signals

  3. Examples • Consider g++ myProg.c • You want to kill this process after you started the compilation..hit cntrl-C • Consider execution of a program called “badprog” >badprog It core dumps .. What happened? The error in the program results in a signal to kernel to stop and dump the offending code • Consider “kill –p <pid>” • Kill issues a termination signal to the process identified by the pid

  4. Signals • Signals provide a simple method for transmitting software interrupts to UNIX process • Signals cannot carry information directly, which limits their usefulness as an general inter-process communication mechanism • However each type of signal is given a mnemonic name; Ex: SIGINT • See signal.h for others • SIGHUP, SIGINT, SIGILL, SIGTRAP, SIGFPE, SIGKILL, SIGALRM (sent by kernel to a process after an alarm timer has expired) • SIGTERM

  5. Handling Signals • Look at the examples: • Catching SIGALRM • Ignoring SIGALRM • sigtest.c

  6. Signals and Alarms #include <unistd.h> unsigned int alarm( unsigned int seconds ); alarm(a); will start a timer for a secsonds and will interrupt the calling process after a secs. time(&t); will get you current time in the variable t declared as time_t t ctime(&t); will convert time to ascii format

  7. Sample program • Lets look at a sample program

  8. Volatile • A variable should be declared volatile whenever its value could change unexpectedly. In practice, only three types of variables could change: • Memory-mapped peripheral registers • Global variables modified by an interrupt service routine • Global variables within a multi-threaded application

More Related