for s := range signal.Incoming {switch s.(os.UnixSignal) {case syscall.SIGINT:os.Exit(0)case syscall.SIGTSTP:fmt.Printf("\nStopping\n")syscall.Kill(0, syscall.SIGSTOP)fmt.Printf("\nStarting\n")default:fmt.Printf("Signal %s\n", s)}}
^ZStoppingStarting[1] + Stopped (SIGSTOP) ./sig
Making SIGCONT catchable may require existing programs to need to be changed. The signal interface should allow the application to express interest in which signals it handles. I don't see anyway to do that, but it looks like a system specific method of updating runtime·sigtab[signum].flags would probably make this possible.
>>
>> Making SIGCONT catchable may require existing programs to need to be
>> changed. The signal interface should allow the application to express
>> interest in which signals it handles. I don't see anyway to do that, but it
>> looks like a system specific method of updating runtime·sigtab[signum].flags
>> would probably make this possible.
>>
>
> I was under the impression that SIGKILL, SIGSTOP, and SIGCONT are handled
> outside the program and never make it to the binary.
SIGCONT can be caught:
$ cat t.c
#include <signal.h>
#include <unistd.h>
void
handler(int i)
{
write(STDERR_FILENO, "hello\n", 6);
_exit(0);
}
int
main()
{
signal(SIGCONT, handler);
while (1) { }
}
$ gcc -Wall -O2 t.c
$ ./a.out
^Z
[1]+ Stopped ./a.out
fg
./a.out
hello
$
It seems that synchronous delivery of SIGTSTP is not guaranteed on
some systems, so catching SIGCONT is the only reliable way to redraw
the screen when a suspended process is put into the foreground again.
> I was under the impression that SIGKILL, SIGSTOP, and SIGCONT are handledSIGCONT can be caught:
> outside the program and never make it to the binary.