Wandering Thoughts archives


How you tell what signals a Linux process is ignoring

Suppose that you want to know what processes on your system are ignoring certain signals, such as the SIGTERM that systemd uses to try to get lingering processes to quit. How do you find this out? As with many process-related things in Linux, the answer is that you look in /proc.

Specifically, you look in /proc/<pid>/status and get the SigIgn: field. This is in hex, and may look something like this:

SigIgn: 0000000000004007

(There is also SigCgt: for the signals that the process has installed signal handlers for.)

This is a bitmap of signals. You can see the mapping between signal names and numbers with 'kill -L' (which reports them in decimal), and then use your favorite decimal+hex calculator to work out what bit this corresponds to. Suppose we want SIGTERM, signal 15. I'm a Python person, so:

$ python -c 'print "%x" % (1<<(15-1))'

(We subtract one because signals are numbered starting from 1 instead of 0.)

In this case, the question about our SigIgn: above is very easy; this process is ignoring SIGTERM, but not any other signals around it.

If we want to look at a mass of processes, we can abuse gawk:

cd /proc
gawk '/^SigIgn:/ && (and(strtonum("0x" $2), 0x4000) > 0) {print FILENAME}' */status

Somewhat to my surprise, it turns out that there are quite a few programs on my Linux machine that are ignoring SIGTERM. But how many are ignoring both SIGTERM and SIGHUP (signal 1, and thus it has the mask 0x01)?

cd /proc
gawk '/^SigIgn:/ && (and(strtonum("0x" $2), 0x4001) == 0x4001) {print FILENAME}' */status

Once again there were more than I expected. However, I think I don't notice most of them because they exit if their connection to the X server goes away. The exception is my non-friend kio_http_cache_cleaner, which is apparently so disconnected from everything that it doesn't notice my X session disappearing.

(Perhaps it would if I was running a proper KDE session, or even a Gnome session. Also, now I wonder if I am somehow indirectly starting it in such a way that it ignores more signals than usual, since a number of things in my X session turn out to have the same set of ignored signals as it does.)

Sidebar: seeing what signals a Linux process is ignoring

On some systems, such as Solaris and its descendents, you have a handy psig program that will report all sorts of information about what signals a process is ignoring or catching and what it's doing with them and so on. On Linux, as far as I know, even a basic version is not part of eg procps-ng or similar packages. If you need this information, see eg Erik Weathers' psig, which I found via this popular Stackexchange question and its answers.

I'm probably going to wind up keeping a copy of psig around, as using it on various processes here has already given me things to think about and look into.

linux/WhatSignalsIgnored written at 23:31:55; Add Comment

Page tools: See As Normal.
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.