@@ -420,6 +420,7 @@ OPTIONS
*--daemonize*
Run trace-cmd in the background as a daemon after recording has started.
+ Creates a pidfile at /var/run/trace-cmd-record.pid with the pid of trace-cmd during the recording.
EXAMPLES
--------
@@ -46,6 +46,8 @@
#define _STR(x) #x
#define STR(x) _STR(x)
+#define RECORD_PIDFILE "trace-cmd-record.pid"
+
#define TRACE_CTRL "tracing_on"
#define TRACE "trace"
#define AVAILABLE "available_tracers"
@@ -93,6 +95,8 @@ static bool fork_process;
static bool do_daemonize;
+static bool created_pidfile;
+
/* Max size to let a per cpu file get */
static int max_kb;
@@ -646,6 +650,9 @@ void die(const char *fmt, ...)
else
ret = -1;
+ if (created_pidfile)
+ remove_pid_file(RECORD_PIDFILE);
+
kill_threads();
va_start(ap, fmt);
fprintf(stderr, " ");
@@ -1737,6 +1744,9 @@ static void daemonize_finish(void)
if (kill(getppid(), SIGRTMIN) == -1)
die("daemonize: kill");
+
+ make_pid_file(RECORD_PIDFILE);
+ created_pidfile = true;
}
static void trace_or_sleep(enum trace_type type, bool pwait)
@@ -7225,6 +7235,9 @@ static void record_trace(int argc, char **argv,
destroy_stats();
finalize_record_trace(ctx);
+
+ if (created_pidfile)
+ remove_pid_file(RECORD_PIDFILE);
}
/*
@@ -81,7 +81,9 @@ static struct usage_help usage_help[] = {
" available algorithms can be listed with trace-cmd list -c\n"
" --proxy vsocket to reach the agent. Acts the same as -A (for an agent)\n"
" but will send the proxy connection to the agent.\n"
- " --daemonize run trace-cmd in the background as a daemon after recording has started\n"
+ " --daemonize run trace-cmd in the background as a daemon after recording has started.\n"
+ " creates a pidfile at /var/run/trace-cmd-record.pid with the pid of trace-cmd\n"
+ " during the recording.\n"
},
{
"set",