Skip to content

Instantly share code, notes, and snippets.

@kakwa
Created July 8, 2015 18:01
Show Gist options
  • Save kakwa/3006b62b8a256d787ed1 to your computer and use it in GitHub Desktop.
Save kakwa/3006b62b8a256d787ed1 to your computer and use it in GitHub Desktop.
#!/bin/sh
tmpdir=`mktemp -d`;
[ $? -eq 0 ] || exit 1;
cat >$tmpdir/file.c <<EOF
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char * argv[]){
if (argc <= 1){
printf("missing pid argument\\n");
return 1;
}
int pid = atoi(argv[1]);
printf("killing process: %d\\n", pid);
int ret = kill(pid, SIGTERM);
return ret;
}
EOF
gcc $tmpdir/file.c -o $tmpdir/notkill
$tmpdir/notkill $1
ret=$?
! [ -z "$tmpdir" ] && [ -d "$tmpdir" ] && rm -rf $tmpdir
exit $ret
@kakwa
Copy link
Author

kakwa commented Jul 8, 2015

analog to https://gist.github.com/kakwa/23eef5f44017be15b4f8 (but somewhat readable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment