1 / 10

Advanced UNIX programming

Advanced UNIX programming. Fall 2002 Instructor: Ashok Srinivasan Lecture 11. Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan. Announcements. Reading assignment APUE Chapter 10 Sections 10.8 to 10.14

alyn
Download Presentation

Advanced UNIX 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. Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 11 Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

  2. Announcements • Reading assignment • APUE Chapter 10 • Sections 10.8 to 10.14 • http://www.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_04.html • HW 2 has been announced • Email me the times when you are available, Tuesday and Wednesday

  3. Week 4 Topics • Pipes • Named and unnamed pipes • Implementing pipe in a shell • Signals • Catching signals • signal • Manipulate signal sets • sigemptyset, sigfillset, sigdelset, sigaddset, sigdelset, sigismember • Manipulate signal mask • sigprocmask • sigaction • kill

  4. Signals • Catching signals • signal • Manipulate signal sets • sigemptyset, sigfillset, sigdelset, sigaddset, sigdelset, sigismember • Manipulate signal mask • sigprocmask • sigaction • kill

  5. Manipulate signal sets • #include <signal.h> int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo);

  6. Manipulate signal mask • Manipulate signal mask of a process • int sigprocmask(int how, const sigset_t *set, sigset_t *oset); • how: SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK • set: New set • oset: Old set • See example2.c and example3.c

  7. Example: Blocking signals in a critical region • For a critical region where you don’t want certain signal to come, the program will look like: sigprocmask(SIG_BLOCK, &newmask, &oldmask); ……. /* critical region */ sigprocmask(SIG_SETMASK, &oldmask, NULL);

  8. sigaction • Supersedes the signal function • #include <signal.h> • int sigaction(int signo, const struct sigaction * act, struct sigaction *oact) • struct sigaction { void (*sa_handler)(); /* signal handler */ sigset_t sa_mask; /*additional signal to block */ int sa_flags; /* options: we will set it to 0 */ sa_sigaction; /* we will not use it */ }; • See example4.c

  9. kill • Send a signal to a process • #include <signal.h> • #include <sys/types.h> • int kill(pid_t pid, int signo); • See example5.c • See example6.c for the use of alarm

  10. Impact of signals on system calls • A system call may return prematurely • See example7.c • How can we deal with this problem? • Check the return value of the system call and act accordingly

More Related