Originally Posted by
rstanley
Post a full program that fails, using your code, and let us know what compiler you are using.
This is your code, but I added endless while loop and print to file. It also stops working after about 15 minutes. gcc compiler.
Code:
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(void)
{
FILE *log = NULL;
time_t start = 0;
time_t stop = 0;
time_t tdif = 0;
while(1){
time(&start);
log=fopen("./log.txt","a");
do{
time(&stop);
tdif=difftime(stop, start);
printf(" %ld, localtime %s\n", tdif, asctime(localtime(&stop)));
fprintf(log," %ld\n, localtime %s\n", tdif,asctime(localtime(&stop)));
sleep(1);
}
while(tdif<32);
fclose(log);
}
return 0;
}
Originally Posted by
Salem
> I'm writing to a file because I don't have ssh when I shut down wifi for that one raspberry pi.
So how are you running your program from your ssh session?
If you're just putting it into the background using say
./myprog &
That isn't going to be enough if you then exit ssh.
You need this.
Linux nohup command help and examples
nohup ./myprog &
Yes, I did exactly that. I thought the program will continue runing after ssh pipe breaks. Of course, later I planned to start it at startup. I'll try this.