USG 5.0 r2: can my program tell if it is in background/nohup'd?

Paul A. Sherman sherm at phoenix.UUCP
Fri Aug 10 23:58:33 AEST 1984


>    Is there any way for me to make some test and see if I am running in
>    the background?  I have an assembler package that calls m4(1), runs
>    my own yacc/lex preprocessor, passes pseudocode onto a meta-assembler,
>    and conditionally calls a linkage editor.  I catch SIGINT because I
>    need to do tempfile cleanup, but when this package is run nohup'd in
>    the background and the user hits a delete or break in his login shell,
>    the interrupt punches through nohup (nohup does nothing with signal 2)
>    and kills the nohup'd process!!

Although nohup doesn't do anything with signal 2, putting something in the
background with "&" normally ignores it.  You are causing it not to be ignored
when you call your own routine to handle SIGINT.

What you should do is check to see if SIGINT was already being ignored
when you try to handle it.  (This indicates that you're in the background.)
If it was being ignored, reset it to that state.

	if (signal(SIGINT, clean_routine) == SIG_IGN)
		signal(SIGINT, SIG_IGN);

Paul Sherman	AT&T Information Systems, Lincroft, NJ     phoenix!sherm
-- 



More information about the Comp.unix.wizards mailing list