Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/usr/bin/env python3.6
  2. import ctypes as ct
  3. import argparse
  4.  
  5. #Load Libc
  6. libc = ct.cdll.LoadLibrary("libc.so.6")
  7. #typedef
  8. #see elixir.bootlin.com to find type of pid_t
  9. PID_T = ct.c_int
  10.  
  11. def kill(pid, sig):
  12. #see man 2 kill for information on the function
  13. kilsc = libc.kill
  14. #Always define arg and res types
  15. #Saves a lot of headaches
  16. kilsc.argtypes = [PID_T, ct.c_int]
  17. kilsc.restype = ct.c_int
  18. ret = kilsc(pid, sig)
  19. if ret < 0:
  20. print("FAILED")
  21. exit()
  22.  
  23. def main():
  24. #Quick argparse setup
  25. parser = argparse.ArgumentParser(description="Kill in python")
  26. parser.add_argument("pid", type=int, help="Process")
  27. parser.add_argument("sig", type=int, help="Signal to send")
  28. args = parser.parse_args()
  29. kill(args.pid, args.sig)
  30.  
  31. if __name__ == "__main__":
  32. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement