Download presentation
Presentation is loading. Please wait.
1
Page 1 Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming B. Ramamurthy
2
Page 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
Page 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 ” –Kill issues a termination signal to the process identified by the pid
4
Page 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
Page 5 Handling Signals Look at the examples: Catching SIGALRM Ignoring SIGALRM sigtest.c
6
Page 6 Signals and Alarms #include 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
Page 7 Sample program Lets look at a sample programsample program
8
Page 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.