Recently I have tasked with customizing one of the applications that our groups uses quite regularly. The application is written in C, something that I don't have a whole lot of experience in. I have found some functional examples of what I am trying to do but as of yet have been unable to integrate it fully into my test bed.
The requirement is quite simple: open a named pipe and push some data out so that another group can read the pipe and do something with it. This has to be done such that it doesn't interrupt the server from doing its thing.
My application has an array called history which contains all the necessary values that I am after. I have so far had mixed results with my attempts at accomplishing this. Please see below snippet of code:
DCmass_add_history(history, history_num);
int fd;
char * myfifo = "/tmp/fooPipe";
/* create the FIFO (named pipe) */
mkfifo(myfifo, 0666);
/* open FIFO (named pipe) */
fd = open(myfifo, O_WRONLY);
for (i = 0; i < history_num; i++) {
/* Write our data to our FIFO (named pipe) */
fprintf(fd, "%d %d %f %f", history[i].id, history[i].clock, history[i].value, history[i].ns);
}
close(fd);
I had some success previously when using the write
instead of fprintf
but couldn't get any variables into my pipe.
From a previous stack overflow example, Stack Overflow example I was able to get a basic reader to test my pipe, and the basic code from above to open my pipe.