// watch-n-write.c
// Problem: When the file doesn't exist it should 'Start transmission' and add one to dead. It seems to immediately 'start transmission' even if the file exists. When I get past that I can work on the 'transmission' code segment.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
main(int argc, char *argv[]){
FILE *stream;
char sigstat[20],pidloc[] = "/proc/%s/status",openme[sizeof pidloc+100],buf[100];
int i, dead = 0;
if (argc < 4){
printf("usage: ./watch-n-write pid username tty\n");
exit(1);
}
sprintf(openme, pidloc, argv[1]);
printf("Waiting...");
for (i = 0; dead < 1; i++){
if((stream = fopen(openme,"r")) == NULL){
printf("\nStarting transmission...\n");
dead++;
}
}
} //MAIN