Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- /*
- * mshobeli FIFO-shi wers KODS da elodeba shvils!
- * shvili am KODS igebs da debs "test.c" failshi!
- * amis mere mshobeli akompilirebs "test.c" fails!
- */
- int main()
- {
- printf("[PROGRAM STARTED]\n");
- int pr, status, FIFO, fd;
- char str[] = "#include <stdio.h> #include <stdlib.h> int main() { printf(\"Hello world!\\n\"); return 0; }";
- char str2[92];
- char path[] = "asdf.fifo";
- (void)umask(0);
- FIFO = mknod(path, S_IFIFO | 0754, 0);
- if (FIFO == -1)
- {
- printf("FIFO was not created!\n");
- exit(-1);
- }
- pr = fork();
- if (pr == -1) exit(-1);
- if (pr != 0) // PARENT PROCESS
- {
- printf("[PARENT]:\n");
- fd = open(path, O_WRONLY);
- if (fd == -1) exit(-1);
- if (write(fd, str, sizeof(str)) != sizeof(str)) exit(-1);
- close(fd);
- wait(&status);
- execl("usr/bin/gcc", "gcc", "test.c", "-o", "test.out", NULL);
- printf("[END OF PARENT]\n");
- }
- else // CHILD PROCESS
- {
- printf("[CHILD]:\n");
- fd = open(path, O_RDONLY);
- if (fd == -1)
- {
- printf("FD problem!");
- exit(-1);
- }
- if (read(fd, str2, sizeof(str2)) != sizeof(str2)) exit(-1);
- close(fd);
- (void)umask(0);
- fd = open("test.c", O_WRONLY | O_CREAT, 0756);
- if (fd == -1) exit(-1);
- if (write(fd, str2, sizeof(str2)) != sizeof(str2)) exit(-1);
- close(fd);
- printf("[END OF CHILD]\n");
- }
- printf("[PROGRAM ENDED]\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment