Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!ll-xn!cit-vax!tybalt.caltech.edu!sns
From: sns@tybalt.caltech.edu (Samuel N. Southard)
Newsgroups: comp.unix.xenix
Subject: job completion notification
Message-ID: <3264@cit-vax.Caltech.Edu>
Date: Fri, 17-Jul-87 07:20:01 EDT
Article-I.D.: cit-vax.3264
Posted: Fri Jul 17 07:20:01 1987
Date-Received: Sat, 18-Jul-87 13:15:05 EDT
Sender: news@cit-vax.Caltech.Edu
Reply-To: sns@tybalt.caltech.edu (Samuel N. Southard)
Distribution: world
Organization: Calfornia Institute of Technology
Lines: 52

I have IBM Xenix 2.00 and I got tired of always having to do a ps to see if a
job I had put int the background had completed yet, so I wrote this utility.
It is very trivial and short, so I'm poisting it here.  When the job is
complete it will print a message to the terminal, regardless of output
redirection.

/*	done - a program executed in the background with this program will send
	a message when the program has completed */

#include 
#include 

main(argc,argv)
int argc;
char	*argv[];
{
	int	jobid,status;
	FILE *term;

	if (argc>1)
	{
		jobid=fork();
		if (jobid<0) /* the fork failed */
		{
			perror("fork");
			exit(2);
		}
		if (jobid==0)	/* the child */
		{
			execvp(argv[1],&argv[1]);
			perror(argv[1]); /* couldn't exec */
			exit(1);
		} else {
			term=fopen("/dev/tty","a");
			fprintf(term,"Job %d submitted.\n",jobid);
			wait(&status);
			if (status & 0xff) /* received a signal */
				fprintf(term,"\nProcess %d received signal %d\n",jobid,status & 0xff);
			else if (status >> 8) /* exited */
				fprintf(term,"\nProcess %d stopped due to exit(%d)\n",jobid,status >> 8);
			else /* normal exit */
				fprintf(term,"\nProcess %d completed normally\n",jobid);
			exit(status >> 8);
			fclose(term);
		}
	} else { /* no command given */
		fprintf(stderr,"usage: done command\n",20);
		exit(1);
	}
}

My cat can quack, can yours?		genghis!sns@csvax.Caltech.Edu