Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!emory!tridom!wht From: wht@tridom.uucp (Warren Tucker) Newsgroups: alt.sources Subject: godot.c - pid watcher Keywords: XENIX multiscreen theater_of_the_absurd Message-ID: <143@tridom.uucp> Date: 13 Jul 89 14:54:41 GMT Organization: Tridom Corporation, Marietta GA Lines: 168 If flames about job control doing a better job occur, let the potential knee jerk blabberer make job control show up under XENIX or make job control watch a UUCP session owned by root. In other words, I don't want to see discussion about this program under alt.sources even if it causes you to reach Nirvana and 72000 orgasms. I agree with a previous poster that rather than dis{cuss,gust} the disgusting disCUSSion going on here, post sources. Since alt.sources has taken on the flavor of the Theatre of the Absurd lately, I offer godot.c, named after the famous Godot certain spouters seems to be waiting on to stop gabbing. So stop gabbing I shall; let there be source. #!/bin/sh # shar: Shell Archiver (v1.22) # # Run the following text with /bin/sh to create: # godot.c # if test -f godot.c; then echo "File godot.c exists"; else echo "x - extracting godot.c (Text)" sed 's/^X//' << 'SHAR_EOF' > godot.c && X/* CHK=0x08F4 */ Xchar numeric_revision[] = "1.20"; X/*+----------------------------------------------------------------- X godot.c X ...!gatech!emory!tridom!wht X XInstead of waiting for Godot, let's make Godot wait. This program Xwaits for a process to disappear and then print a message. Under XXENIX, it prints a message on all the multiscreens. Under BSD, it Xjust prints one message to stdout. X Xcc -O godot.c -o godot X------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:07-13-1989-10:43-wht-send to alt.sources */ X X#include X#include X#include X Xextern int errno; Xint pid_to_watch; Xint forkpid; Xchar reason_string[512]; X X/*+------------------------------------------------------------------------- X usage() X--------------------------------------------------------------------------*/ Xusage() X{ X fprintf(stderr, X "usage: godot [text to print at termination]\n"); X exit(1); X} /* end of usage */ X X/*+----------------------------------------------------------------- X bell(count) X------------------------------------------------------------------*/ Xvoid Xbell(count) Xint count; X{ X if(count == 0) X count = 1; X X while(count--) X { X fputc(0x07,stderr); X sleep(1); X } X} X X/*+------------------------------------------------------------------------- X xenix_notify(pid_that_died) X Under XENIX, write termination message to tty01-tty10 X--------------------------------------------------------------------------*/ X#if defined(XENIX) Xxenix_notify(pid_that_died) Xint pid_that_died; X{ X char devname[64]; X FILE *dev_fp; X int devnum; X X for(devnum = 1; devnum < 12; devnum++) X { X sprintf(devname,"/dev/tty%02d",devnum); X if((dev_fp = fopen(devname,"a")) != NULL) X { X fputc(7,dev_fp); X fprintf(dev_fp,"\r\nGODOT: %s%s%s pid %d terminated\r\n", X (strlen(reason_string)) ? "(" : "", X reason_string, X (strlen(reason_string)) ? ")" : "", X pid_that_died); X sleep(1); X fputc(7,dev_fp); X fclose(dev_fp); X } X } X X} /* end of xenix_notify */ X#endif X X/*+------------------------------------------------------------------------- X main(argc,argv,envp) X--------------------------------------------------------------------------*/ Xmain(argc,argv,envp) Xint argc; Xchar **argv; Xchar **envp; X{ X register int iargv; X X fprintf(stderr,"godot %s\n",numeric_revision); X if(argc == 1) X usage(); X X sscanf(argv[1],"%d",&pid_to_watch); X X for(iargv = 2; iargv < argc; iargv++) X { X strcat(reason_string,argv[iargv]); X if(iargv != (argc - 1)) X strcat(reason_string," "); X } X if(pid_to_watch == 0) X usage(); X fprintf(stderr,"This is godot (pid %d): I am watching pid %d (%s)\n", X getpid(0),pid_to_watch,reason_string); X while(1) X { X sleep(5); X if(kill(pid_to_watch,0) < 0) X { X if(errno != ESRCH) X continue; X#if defined(XENIX) X xenix_notify(pid_to_watch); X#else X bell(2); X fprintf(stderr,"\r\nGODOT: %s%s%s pid %d terminated\r\n", X (strlen(reason_string)) ? "(" : "", X reason_string, X (strlen(reason_string)) ? ")" : "", X pid_to_watch); X bell(2); X#endif X exit(0); X } X } X} /* end of main */ X X/* vi: set tabstop=4 shiftwidth=4: */ X/* end of godot.c */ SHAR_EOF chmod 0644 godot.c || echo "restore of godot.c fails" fi exit 0 -- ------------------------------------------------------------------- Warren Tucker, Tridom Corporation ...!gatech!emory!tridom!wht Sforzando (It., sfohr-tsahn'-doh). A direction to perform the tone or chord with special stress, or marked and sudden emphasis.