sosy-lab / cpu-energy-meter

A tool for measuring energy consumption of Intel CPUs
BSD 3-Clause "New" or "Revised" License
321 stars 29 forks source link

SIGINT problems #22

Closed antondalgren closed 5 years ago

antondalgren commented 5 years ago

Hi

I'm using this tool to measure the energy usage of the CPU in benchmark suite. I'm having trouble to send the SIGINT signal to the process.

Im using python3 for this and both running the multiprocessing module and the subprocess module as seen below.

def start_CPU_measure():
  print(" -------- Starting CPU measure ----------")
  p = multiprocessing.Process(target=worker, args=( ))
  p.start()
  print(" -------- Done with CPU measure ----------")

def worker():
  measure_process = subprocess.Popen(args=["cpu-energy-meter", "-d"], shell=True)
  time.sleep(5)
  measure_process.send_signal(signal.SIGINT)

Do you have any suggestions on how to get this SIGINT to actually get through?

PhilippWendler commented 5 years ago

The problem is shell=True. Python spawns a shell, which then spawns cpu-energy-meter, and the signal is sent to the shell instead of cpu-energy-meter. Without this, it works.

In general, one should avoid shell=True anyway for security reasons.

Note that if you call cpu-energy-meter from another process and want to parse its arguments, make sure to pass -r (and not -d).

antondalgren commented 5 years ago

@PhilippWendler Yes thats it, thanks alot!