[comp.unix.questions] Need help with SIGSTP signal handing

weil@dataio.UUCP (03/31/87)

I have a screen oriented application program running under UNIX (4.2)
and I would like to allow it to handle the suspend signal (^Z) gracefully.
The difficulty is that it gets called form a (bourne) shell script, not
directly from the command line.

The original code we used (from dpy) looked like:

initialize()
{
    ...
    signal(SIGTSTP, stop);
    ...
}

stop()
{
    move_cursor_to_bottom_line();
    reset_to_original_terminal_modes();

    kill( getpid(), SIGSTOP);

    /* suspend occurs here */

    set_new_terminal_modes();
    redraw_screen();
}

This works fine when you run the program from the command line, but when
it is invoked from a shell script, the cursor moves to the bottom line,
but we get neither a shell prompt, or ever return to the application program.


Then I looked at popular program and tried some code like this:

stop()
{
    move_cursor_to_bottom_line();
    reset_to_original_terminal_modes();

    setsigmask(0);
    signal( SIGTSTP, SIG_DFL);
    kill( 0, SIGTSTP);

    /* suspend occurs here */

    signal (SIGTSTP, stop);

    set_new_terminal_modes();
    redraw_screen();
}

This also works fine when I run the program directly from the command line,
but when run from a shell script, it requires two 'fg' commands to restart
the program.  It looks like this:

^Z
Stopped
% fg
my_application_name

Stopped
% fg
<then it really start up>


Could someone please explain what is going on.  My understanding is that the
bourne shell does nothing with the suspend signal, so it should be suspended
and restarted along with my application.  Attempts to catch or ignore
the signal using the trap command in the shell script have also been
unfruitful.

(I should mention that development is on a SUN running release 2, but
I see the same problems on a VAX.)


Thanks,
			Steve Weil
			uw-entropy!dataio!weil