From 7cd729ec78f03485e040b13a9336ba5283d51fe9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 19 Jan 2025 16:29:12 -0800 Subject: vmon: monitor vmon's PID when reaper and executor If vmon ran a command as its child and was told to be the reaper, we probably want to see any inherited orphans vmon becomes responsible for reaping in the graph. The simplest robust way to achieve this is to monitor vmon's PID as the root instead of the pid of the command being executed. There's an argument to be made that this is how it should always be done when executing a command, but for now I'm only going to do it when being the reaper. I think there's also an argument to be made that becoming a subreaper should also be the default when executing a command. --- src/vmon.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/vmon.c b/src/vmon.c index 347d5d3..927323b 100644 --- a/src/vmon.c +++ b/src/vmon.c @@ -698,10 +698,23 @@ static vmon_t * vmon_startup(int argc, const char * const *argv) goto _err_win; } - vmon->chart = vwm_chart_create(vmon->charts, vmon->pid ? : 1, vmon->width, vmon->height, vmon->name); - if (!vmon->chart) { - VWM_ERROR("unable to create chart"); - goto _err_win; + { + pid_t root_pid = 1; + + if (vmon->pid) + root_pid = vmon->pid; + + /* If vmon is executing the command and being the reaper, make vmon itself the monitored root. + * This way we get to see any orphans. + */ + if (vmon->execv && vmon->reaper) + root_pid = getpid(); + + vmon->chart = vwm_chart_create(vmon->charts, root_pid, vmon->width, vmon->height, vmon->name); + if (!vmon->chart) { + VWM_ERROR("unable to create chart"); + goto _err_win; + } } if (vmon->mem_locked) { -- cgit v1.2.3