Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3.6
- import ctypes as ct
- import argparse
- #Load Libc
- libc = ct.cdll.LoadLibrary("libc.so.6")
- #typedef
- #see elixir.bootlin.com to find type of pid_t
- PID_T = ct.c_int
- def kill(pid, sig):
- #see man 2 kill for information on the function
- kilsc = libc.kill
- #Always define arg and res types
- #Saves a lot of headaches
- kilsc.argtypes = [PID_T, ct.c_int]
- kilsc.restype = ct.c_int
- ret = kilsc(pid, sig)
- if ret < 0:
- print("FAILED")
- exit()
- def main():
- #Quick argparse setup
- parser = argparse.ArgumentParser(description="Kill in python")
- parser.add_argument("pid", type=int, help="Process")
- parser.add_argument("sig", type=int, help="Signal to send")
- args = parser.parse_args()
- kill(args.pid, args.sig)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement