#define _GNU_SOURCE #include #include #include #include #include #include #include int main(int argc, char * argv[]){ int targetpid; int targetgid; char* procplace; struct stat st; if (argc != 2){ fprintf(stderr, "error - require exactly 1 argument\n"); return 1; } if (sscanf(argv[1], "%i", &targetpid) != 1) { fprintf(stderr, "error - argv[1] not an integer\n"); return 2; } if (group_member(getegid()) == 0) { fprintf(stderr, "error - User is not part of the egid group %d\n", getegid()); return 3; } // todo check if pid exists procplace = (char*) malloc(16*sizeof(char)); sprintf(procplace, "/proc/%d", targetpid); stat(procplace, &st); targetgid = st.st_gid; free(procplace); printf("pid: %d gid: %d\n", targetpid, targetgid); procplace = NULL; if (targetgid != getegid()){ fprintf(stderr, "error - target gid is not equal to our egid. %d != %d\n", targetgid, getegid()); return 4; } printf("Killing %d\n", targetpid); kill(targetpid, SIGTERM); }