stop.py 456 B

12345678910111213141516171819202122
  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import psutil
  4. def main():
  5. try:
  6. with open("pid", "r") as f:
  7. text = f.read().replace("\n", "").replace("\r", "")
  8. pid = int(text)
  9. with open("pid", "w") as f:
  10. f.write("")
  11. for proc in psutil.process_iter():
  12. if proc.pid == pid:
  13. proc.kill()
  14. except Exception as e:
  15. print(e)
  16. if __name__ == '__main__':
  17. main()