Re: kvm_stat issue running in the background

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Aug 03, 2024 at 11:23:21AM +0200, Claudio Fontana wrote:
> Hello Stefan,
> 
> did not know where to report this, but the man page mentions you specifically so here I am.

Hi Claudio,
I wrote the man page for kvm_stat(1) but am not the maintainer of the
tool. I have CCed the KVM mailing list although it's possible that no
one actively maintains the tool :).

> 
> 
> There seems to be an issue when kvm_stat is run with:
> 
> kvm_stat -p xxx -d -t -s yy -c -L FILENAME.csv &
> 
> specifically due to the ampersand (&), thus running in the background.
> 
> 
> It seems that kvm_stat gets the interrupt signal (SIGINT), and does write as a result the output to disk,
> but then instead of terminating, it just hangs there forever.

That is strange. The only signal handler installed by kvm_stat is for
SIGHUP, so Python should perform the default behavior for SIGINT and
terminate. I'm not sure why the process would hang.

> 
> So to avoid ending up with a large number of kvm_stat processes lingering on the system,
> we needed to put a random sleep, and then send a SIGTERM to terminate the kvm_stat processes.
> 
> Just sending a SIGTERM (without the SIGINT) does terminate the kvm_stat processes, but NO DATA is written to disk (the files show as 0 size).

That makes sense since kvm_stat does not handle SIGTERM. The default
SIGTERM behavior is to terminal and any output in Python's I/O buffers
may not have been written to the file.

Maybe kvm_stat should catch SIGINT and SIGTERM. That would give it a
chance to write out the log before terminating. Do you want to try
implementing that?

> 
> This is the workaround script that we currently have:
> 
> ----
> 
> #! /bin/bash                                                                                                            
> 
> VM_PIDS=`pgrep qemu-system-`
> 
> for VM_PID in ${VM_PIDS} ; do
>     # warning: kvm_stat is very fragile, change with care                                                               
>     kvm_stat -p ${VM_PID} -d -t -s 1 -c -L kvm_stat_${VM_PID}.csv &
> done
> 
> if test "x${VM_PID}" != "x" ; then
>     echo "launched kvm_stat processes, capturing 10 seconds..."
>     sleep 10
>     echo "signaling all kvm_stat processes to write to disk..."
>     pkill -INT -P $$
>     sleep 5
>     sync
>     echo "signaling all kvm_stat processes to die..."
>     pkill -TERM -P $$
>     echo "waiting for kvm_stat processes to exit..."
>     while pgrep -P $$ > /dev/null; do
>     sleep 2
>     echo "still waiting for kvm_stat processes to exit..."
>     done
> fi
> 
> echo "Done."
> 
> ----
> 
> Feel free to forward to the appropriate mailing list if needed,
> 
> thanks!
> 
> Claudio
> 
> -- 
> Claudio Fontana
> Engineering Manager Virtualization, SUSE Labs Core
> 
> SUSE Software Solutions Italy Srl
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux