3

I'm familiar that DD command doesn't produce output while running. However, if I send a USR1 signal to it, it can print current state.

Can I do the same with AWK? Prints its variables, register signal_handler?

5

You can't rely on this behavior across platforms, even for dd. POSIX doesn't specify a response to SIGUSR1, and indeed your dd process will die if you try it on OSX or BSD, or even sometimes on embedded Linux (Busybox). Using SIGUSR1 on dd in this way appears to be a GNU extension. In practice, on most desktop Linux systems you'll be able to do this.

Similarly, if you're using GNU awk, you may be able to send it a SIGUSR1 to get some GNU-specific internal state info. In this case it doesn't print to stdout, but to a file. Awk versions that support this are GNU awk 4.1.0 and later if run with the -p (--profile) flag, or 3.1 and later when compiled and run as pgawk.

For details of what the signals do, see the gawk man page (version 3.1 or version 4.1), and search for "Signals".

Note that it's less certain that your desktop Linux is running GNU awk than GNU dd; mawk is another awk I've seen running on desktop Linux.

  • 1
    Note: The provided man-page link speaks only about pgawk, the GNU awk spinoff: "pgawk accepts two signals.". - But since the features of pgawk merged into the newer versions 4.x of GNU awk you can find it in the official manual: gnu.org/software/gawk/manual/gawk.html - The feature is used in context of dynamic profilling. – Janis Jun 17 '15 at 5:13
  • @Janis: Nicely spotted! I've updated the answer to include some version info. – Jander Jun 17 '15 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.