Lecture 16 Signals - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Lecture 16 Signals

Description:

Lecture 16. Signals. Topics. Shell operations. Shell ... CSCE 510 Fall 2005. Zombies and Fireman. signal(SIGCHLD, fireman); /* this eliminates zombies ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 11
Provided by: mantonm5
Category:

less

Transcript and Presenter's Notes

Title: Lecture 16 Signals


1
Lecture 16Signals
CSCE 510 Systems Programming
  • Topics
  • Shell operations
  • Shell implementation
  • Redirecting I/O

October 11, 2005
2
  • Last Time
  • Multiple Pipes implementation
  • Today
  • Filename expansion implementation re_comp,
    re_exec
  • Program 2

3
Signal Sets
4
Sigaction Table
  • struct sigaction
  • void (sa_handler) __(()) / signal handler, or
    action value /
  • sigset_t sa_mask / signals to block while in
    handler /
  • int sa_flags / signal action flags /
  • int sa_signo / signal number /

5
  • include ltsignal.hgt
  • int sigaction(int signum, const struct sigaction
    act, struct sigaction oldact)
  • int sigprocmask(int how, const sigset_t set,
    sigset_t oldset)
  • int sigpending(sigset_t set)
  • int sigsuspend(const sigset_t mask)

6
Sigmask0.c
  • include ltsetjmp.hgt
  • include ltsignal.hgt
  • main()
  • sigset_t sigset, oldset
  • sigemptyset(sigset)
  • sigaddset(sigset, SIGINT)
  • if(sigprocmask(SIG_SETMASK, sigset, oldset)
    lt 0)
  • fprintf(stderr, "sigprocmask ERROR\n")
  • exit(1)
  • sleep(5)
  • if(sigismember(sigset, SIGINT))
    printf("SIGINT MASKED\n")
  • else printf("SIGINT NOT MASKED\n")

7
Sigmask1.c
  • main()
  • sigset_t sigset, oldset, newset
  • int pid
  • sigemptyset(sigset)
  • sigaddset(sigset, SIGINT)
  • if(sigprocmask(SIG_SETMASK, sigset, oldset)
    lt 0) fatal("sigprocmask")
  • if((pid fork()) lt 0) fatal("Fork failed")
  • else if (pid 0)
  • sleep(3)
  • if(sigpending(newset)lt 0)
    fatal("SIGpending")
  • if(sigismember(newset,SIGINT))
  • printf("SIGINT signal is pending\n")
  • else
  • if(kill(pid, SIGINT)lt 0) fatal("Fork
    failed") / sigsend on SUNs /

8
SigQueued.c
if((pid fork()) lt 0) fatal("Fork failed")
else if (pid 0) for(i0 i lt 100
i) sleep(1)
printf("Finished sleeping\n") else
for(inumSignals i gt 0 --i)
if(kill(pid, SIGUSR1)lt 0) fatal("Kill failed")
wait(NULL) void onintr(int sig)
fprintf(stderr,"Sig d Caught d times\n",
sig, countSigs)
  • void onintr(int)
  • int countSigs 0
  • main(int argc, char argv)
  • sigset_t sigset, oldset, newset
  • int pid
  • struct sigaction act, oact
  • int i
  • int numSignals
  • if(argc ! 2) fatal("Usage sigtest num")
  • numSignals atoi(argv1)
  • act.sa_handler onintr
  • sigaction(SIGUSR1, act, NULL)

9
Zombies and Fireman
  • signal(SIGCHLD, fireman) / this eliminates
    zombies / .....
  • / as children die we should get catch their
    returns or else we get zombies, A Bad Thing.
    fireman() catches falling children. /
  • void fireman (int sig)
  • int wstatus
  • int pid
  • while ((pidwaitpid(0,wstatus, WNOHANG)) gt 0)
    fprintf(stderr,"SIGCHLD child d returned
    d\n",pid, WEXITSTATUS(wstatus ))

10
SigSetjmp
  • NAME
  • setjmp, sigsetjmp - save stack context for
    non-local goto
  • SYNOPSIS
  • include ltsetjmp.hgt
  • int setjmp(jmp_buf env)
  • int sigsetjmp(sigjmp_buf env, int
    savesigs)
  • If savesigs is nonzero, the set of blocked
    signals is saved in env and will be restored if a
    siglongjmp() is later performed with this env.
Write a Comment
User Comments (0)
About PowerShow.com