Created
July 8, 2015 18:01
-
-
Save kakwa/3006b62b8a256d787ed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
analog to https://gist.github.com/kakwa/23eef5f44017be15b4f8 (but somewhat readable)