#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#define db 0
void debug(int desc, char * tekst, char * pid) {
char *MSG= (char *) malloc((2 + strlen(pid) + strlen(tekst)));
strcpy(MSG, pid);
strcat(MSG, "\n");
strcat(MSG, tekst);
write(desc, MSG, (int)strlen(MSG));
}
int main(int argc, char *argv[]) {
pid_t parent = getppid();
char parent_str[20];
sprintf(parent_str, "%d", parent);
pid_t pid = getpid();
char pid_str[20];
sprintf(pid_str, "%d", pid);
int inst;
if(db == 1) inst = open("test.txt", O_CREAT | O_WRONLY | O_APPEND , S_IRUSR | S_IWUSR);
int fd;
if((mkfifo(parent_str, S_IRWXU | S_IRWXG | S_IRWXO)) != 0) {
if(errno == EEXIST) {
if(db == 1) debug(inst, " READER. Fifo DUZE juz stworzone. Otwieram do odczytu.\n", pid_str);
if((fd = open(parent_str, O_RDONLY)) == -1) exit(1);
} else {
exit(1);
}
} else {
if(db == 1) debug(inst, " READER. Fifo DUZE nie stworzone. Tworzę i otwieram do odczytu.\n", pid_str);
if((fd = open(parent_str, O_RDONLY)) == -1) exit(1);
}
char buf[20];
if(db == 1) debug(inst, " READER. Za chwile zaczne czytanie z fifo.\n", pid_str);
while (read(fd, &buf, 20) > 0) {
int p = 0;
while(buf[p] != ' ') p++;
buf[p] = '\n';
write(1, buf, p + 1);
}
if(db == 1) debug(inst, " READER. Skonczylem czytac z duzego fifo bo dostalem eof.\n", pid_str);
if(db == 1) close(inst);
close(fd);
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}