I'm trying to use the linux performance tool perf to monitor kvm events on a host where a guest VM exists.
The command I invoke perf is 
perf kvm stat record
After some time, I'll press Ctrl + C to stop it and it will show some info like how many times it has been waken up to write data, and it will spend some time before truly exiting, which I suppose it's writing data.
Basically what I want to achieve is automatically stop the perf process after 1 minute. Here is a prototype of my script:
perf kvm stat record &
pid=$!
sleep 60
sudo kill -2 $pid
The problem here is when I terminate the process in this way, it won't properly write data to disk.And I've tried to send signal 2 and 9, neither works for me.
Does anyone know how to properly interrupt perf process so that it will finish writing data then exit?