16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Processes II<br />

}<br />

pause(); /* wait for a signal */<br />

void sigintHandler()<br />

{<br />

printf("process %d got a SIGINT\n", getpid());<br />

}<br />

parent PID 583 PGRP 583 waits<br />

child PID 584 PGRP 583 waits<br />

^C<br />

process 584 got a SIGINT<br />

process 583 got a SIGINT<br />

/* proc_group2.c */<br />

#include <br />

#include <br />

void sigintHandler();<br />

main()<br />

{<br />

int i;<br />

signal (SIGINT, sigintHandler); /* handle ^C */<br />

}<br />

if (fork() == 0)<br />

setpgrp(0, getpid()); /* place child in own process group */<br />

printf("process PID %d PGRP %d waits\n", getpid(), getpgrp(0));<br />

sleep(5); /* time to ^C */<br />

for (i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!