0

A similar question is already asked here, but my question is very specific: I don't have a PID, but a PID file. Is there a cleaner way of doing this other than reading the file myself? Preferably without an extra module to install.

To avoid an XY problem, what I really want to do is to issue this in Python: pkill -HUP rsyslogd. I am asking because I thought of os.kill(pid_file, signal.SIGHUP), but if there is a different idea for doing what I want, that's more than welcome.

Community
  • 1
  • 1
OmarOthman
  • 1,718
  • 2
  • 19
  • 36

1 Answers1

1

The PID file just contains only the PID? This should work:

 pid = int(open(PID_FILE).read())
eduffy
  • 39,140
  • 13
  • 95
  • 92
  • Thanks, that I know. I wanted to see if there is a better way (in other words, a built-in function that handles this and takes care of all what can go wrong while doing a file operation, possibly handling retries for example, since this is quite a common scenario). What you wrote will fail if the file operation fails and you have to handle the retries yourself. – OmarOthman Apr 06 '16 at 13:21