Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site kovacs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ittvax!dcdwest!sdcsvax!sdcrdcf!randvax!kovacs!rivero From: rivero@kovacs.UUCP (Michael Foster Rivero) Newsgroups: net.sources Subject: new improved zap Message-ID: <212@kovacs.UUCP> Date: Sun, 28-Apr-85 13:36:01 EDT Article-I.D.: kovacs.212 Posted: Sun Apr 28 13:36:01 1985 Date-Received: Thu, 2-May-85 01:39:20 EDT Organization: Robt Abel & Assoc, Hollywood Lines: 60 ------------------ I assumed everybody had their own copy of "zap" from K & P, but since we're in a posting mode, here is our version of zap, which not only kills, but can send a stop and continue signal to programs. -------------------------------------------------------------------------- #include #include char *progname; char *ps = "ps -ag"; main(argc, argv) int argc; char *argv[]; { FILE *fin, *popen(); char buf[BUFSIZ]; char a; int pid; long hpid; progname = argv[0]; if((fin = popen(ps,"r")) == NULL) { fprintf(stderr,"%s: Cannot run %s \n",progname,ps); exit(1); } fprintf(stderr," k for kill ; s for stop ; c for continue.\n"); hpid = getpid(); fgets(buf, sizeof buf, fin); fprintf(stderr, "%s",buf); while(fgets(buf, sizeof buf, fin) != NULL) if(argc == 1 || strindex(buf, argv[1]) >= 0) { buf[strlen(buf)-1] = '\0'; sscanf(buf, "%d", &pid); if(pid != hpid ){ fprintf(stderr, "%s? ",buf); a = ttyin(); if(a == 'k') kill(pid,SIGKILL); if(a == 's') kill(pid,SIGSTOP); if(a == 'c') kill(pid,SIGCONT); } } exit(0); } ------------------------------------------------------- Michael Rivero Robert Abel and Associates randvax!kovacs!rivero