postgresql bgworker SIGTERM handler called twice Im using postgresql 10.1 on Mac.

I have a trouble in terminating a background worker using SIGTERM. In my project, im creating a new background worker using RegisterBackgroundWorker(). i have included a test_function, as a signal handler for SIGTERM. No other signal handlers are defined.

pqsignal(SIGTERM, test_function)


when i issue pkill -15 postgres, i see that the handler is being called twice. Why does it happen? Am i missing anything??
This is because pkill sends the signal to all processes that match the given name, and Postgres is multi-threaded.

Use regular kill with the process ID of the background process that you wish to nuke.