Let me guess ... you're using zsh not bash?
I wish it was zsh... I tested it with zsh, but with bash (and with low-level kill syscall), I observed the same effect unfortunately.
So it's still a puzzle.
1. Even more, when I send a kill() low-level syscall using e.g. Perl - perl -e 'kill("INT", 16107)' - it is the same.
2. If any other program but psql is used (e.g. vim or my custom Perl script which ignores SIGINT), the effect is not reproducible.
Can it be e.g. readline? Or something related to tty or session settings which psql could modify (I did not find any in the source code though).
=========================
chsh -s /bin/bash
# then kill all terminals
$ PGHOST=127.0.0.1 PGPORT=15432 PGUSER=postgres PGPASSWORD=postgres PGDATABASE=postgres /tmp/my1.pl
...
postgres=#
$ ps | grep zsh | grep -v grep
<empty>
$ watch -n0.5 'pstree | grep -E "yarn|psql|vim|sleep|lldb|my.pl|perl|debugserver|-bash| login" | grep -v grep'
| |-+= 13721 root login -fp dmitry
| | \-+= 13722 dmitry -bash
| |-+= 13700 root login -fp dmitry
| | \-+= 13701 dmitry -bash
| | \-+= 16105 dmitry /usr/bin/perl -w /tmp/my1.pl
| | \-+- 16106 dmitry /usr/bin/perl -w /tmp/my2.pl
| | \--- 16107 dmitry psql
| \-+= 13796 root login -fp dmitry
| \--= 13797 dmitry -bash
$ perl -e 'kill("INT", 16107)'
I observe as previously:
int in my2
int in my1
postgres=#
=========================
When I use a custom SIGINT-trapping script instead of psql, it all works as expected in MacOS, only that script receives the SIGINT and not its parents:
=========================
#!/usr/bin/perl -w
$SIG{INT} = sub { print("int ignored\n") };
while (1) { sleep(1); }
$ cat /tmp/my2.pl
#!/usr/bin/perl -w
if (fork()) {
$SIG{INT} = sub { print("int in my2\n") };
while (1) { wait() and exit(1); }
} else {
exec("/tmp/ignore.pl");
}
=========================