sns@tybalt.caltech.edu (Samuel N. Southard) (07/17/87)
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 <stdio.h> #include <ctype.h> 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