From c0cd48a1a6f5c9f4592f5ce215df9c798cb4720a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 6 Feb 2022 18:14:56 -0800 Subject: vmon: add %P fmt specifier for getpid() vmon already handles SIGUSR1 for producing png snapshots on demand, adding a fmt specifier for substituting the vmon PID makes for convenient scripting of triggering such snapshots. i.e: $ vmon -- /bin/bash -c 'for((i = 0; i < 10; i++)); do kill -USR1 %P; sleep 1s; done' Would produce ten png snapshots of the charts on 1-second intervals. --- src/vmon.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vmon.c b/src/vmon.c index 7d0a5f7..59f89ad 100644 --- a/src/vmon.c +++ b/src/vmon.c @@ -345,6 +345,11 @@ static char * arg_interpolate(const vmon_t *vmon, const char *arg) fprintf(memfp, "%s", vmon->output_dir); break; + case 'P': /* getpid() of vmon, convenient for triggering png snapshots on SIGUSR1 */ + /* XXX: note this assumes arg_interpolate() occurs pre-fork, true ATM */ + fprintf(memfp, "%li", (long)getpid()); + break; + case '%': /* literal % */ fputc(c, memfp); break; -- cgit v1.2.3