stop recording and monitor the file creation

  • 17 March 2021
  • 0 replies
  • 16 views

Badge +1

Sometimes you want to stop recording a process before it has finished, leave it running and save what’s been recorded so far.

for example you might want to reproduce a problem that doesn’t end up in a crash on a production system.

Thankfully it is rather easy to stop recording and monitoring when the recording file is stable / complete.

 

There are several processes involved when recording software. Two are relevant for this scenario:

  • live-record
  • nanny

I will not explain what these actually do normally. Let’s just say that live-record is the front-end and nanny the back-end.

By signalling your intention to the front-end the back-end will do what you want.

 

Signalling the intention to stop recording

This is achieved by sending a signal to live-record:

 

$ kill -USR1 <pid of live-record>

 

live-record will then tell nanny to stop recording, detach and save the recording to disk.

 

Monitor the recording creation

 

Nanny will start straight away but it might take some time to completely write the recording to disk.

The most effective way to know the recording has been written is to check when the nanny process disappears:


 

$ while kill -0 "$NANNY_PID" >/dev/null 2>&1; do
sleep 1
done

 

Once the recording is written the loop will finish letting you know you can now do whatever you please with the recording.

 

If we put everything together the result is:

 

#!/bin/bash

# We pass the recording name as parameter in case you want to do something with it
RECORDING_NAME=$1

# Let's obtain the 2 pids of live-record and nanny
LR_PID=$(ps acxu | grep live-record_x64 | awk '{print $2}') # can use "pidof" if available
NANNY_PID=$(ps acxu | grep undo-na | awk '{print $2}') # can use "pidof" if available

# Signal you want to stop recording
kill -USR1 $LR_PID

# Wait for nanny to do its magic
while kill -0 "$NANNY_PID" >/dev/null 2>&1; do
sleep 1 # process is still going, sleep for 1 second
done
echo "Nanny has completed now doing some post processing on ${RECORDING_NAME}"

echo "Your fantasy is your limit"

 


0 replies

Be the first to reply!

Reply