[Vyřešeno] Ako prečíst dáta zo súboru a zapísať je do PIPE-y když proces prijme signál? rubrika: Programování: C/C++
6
Mlocik97
položil/-a 6.1.2019
upravil/-a 8.1.2019
Momentálne mám tento kód a nefunguje správne:
#define _POSIX_SOURCE #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> #include <string.h> int fd, P1; void handler(int signum) { char buff[151], c; size_t i; for (i = 0; (c = getc(fd)) != EOF; i++) { buff[i] = c; } buff[i+1] = '\0'; write(P1, buff, strlen(buff)); } int main(int argc, char *argv[]) { fd = open("p1.txt", O_RDONLY); (void)signal(SIGUSR1, handler); P1 = atoi(argv[1]); const char* textmsg = "P1 SA HLASI KU SLUZBE!"; printf("%s\n", textmsg); kill(getppid(), SIGUSR1); while (1) { sleep(5); } return 0; }
E: už vyřešeno
Pro plný přístup na Devel.cz se prosím přihlaste:
Nebo se přihlaste jménem a heslem:
Komentáře