Programming Assignment 1 - Queues

Programming Assignment 1 - Queues

<p>ECE 329 Handout 1/2</p><p>Using signal()</p><p>The signal function is prototyped in <signal.h> as void (_USERENTRY *signal(int sig, void (_USERENTRY *func)(int sig[, int subcode])))(int); and is used to determine how receipt of signal number sig will subsequently be treated. The signal can be one of several different types of predefined signals. For example, entering “Control-C” from the keyboard, receiving a floating-point arithmetic error, user-defined signals using raise, or a timer interrupt using sigsetjmp (in some compilers/architectures.) ECE 329 Handout 2/2</p><p>Example: #include <stdio.h> #include <stdlib.h> #include <signal.h> // This program runs under Windows typedef void (*fptr)(); int hits = 0; //------void User1Handler(int *reglist) { signal(SIGUSR1, (fptr)User1Handler); // reinstall handler printf("Waiting for Control-C...\n"); } //------void ControlCHandler(int *reglist) { signal(SIGINT, (fptr)ControlCHandler); // reinstall handler</p><p> switch (++hits) { case 1: printf("\tDo you really want to quit?\n"); break; case 2: printf("\tAre you sure?\n"); break; case 3: printf("\tAre you really, really sure?\n"); break; case 4: printf("\tNext time I'm gonna really quit.\n"); break; case 5: printf("\tO.K. I'm qutting...\n"); exit(0); } } //------void main(void) { int i, j;</p><p>// ****** install signal handlers ******** // signal(SIGINT, (fptr)ControlCHandler); // If User decides signal(SIGUSR1, (fptr)User1Handler); // Whenever I Decide</p><p> while (1) { raise(SIGUSR1); for (i=0; i<10000; i++) for (j=0; j<1000; j++) {} } } //------</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us