putting C programs in the background
Morris M. Keesan
keesan at bbncca.ARPA
Sat Jan 19 02:20:26 AEST 1985
-----------------------------
>To put a C program in the background (not from the shell)
>try the following:
>
> if (fork() != 0) exit(0);
>
>Simple yes. Obvious, well maybe. And don't forget to
>setup those signal handlers and file descriptor just right.
>
> Larry Cipriani
> cbscc!cbsch!lvc
Almost. Actually, a little too simple.
Better:
pid = fork();
if( pid < 0 )
{
/* Print error message */
exit(1);
}
else if( pid > 0 )
{
/* parent */
exit(0);
}
/* else pid == 0, this is the child. Continue */
The correct thing to do about signals, to match what the shell does when it
puts something in background, is to ignore SIGINT and SIGQUIT.
--
Morris M. Keesan
{decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan
keesan @ BBN-UNIX.ARPA
More information about the Comp.lang.c
mailing list