Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <string.h>
- #include <unistd.h>
- int line=1;
- void signal_handler() {
- int input=open("bufor", O_RDONLY);
- char buf[100];
- printf("%d ", line);
- line++;
- read(input, buf, 100);
- printf("%s", buf);
- fflush(stdout);
- close(input);
- }
- void end_work(){
- exit(0);
- }
- int main() {
- pid_t pid=fork();
- if(pid == 0) {
- signal(SIGUSR1, signal_handler);
- for(;;);
- }
- else {
- sleep(1);
- char buf[100];
- int output = open("bufor", O_WRONLY | O_CREAT, 0777);
- FILE *input = fopen("/etc/profile", "r");
- while(fgets(buf, 100, input)) {
- write(output, buf, 100);
- memset(buf,0,100);
- kill(pid, SIGUSR1);
- usleep(1000);
- lseek(output, 0L, 0);
- }
- close(output);
- fclose(input);
- remove("bufor");
- kill(pid, SIGUSR2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement