Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <signal.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/ioctl.h>
- FILE *file;
- #define WRITE 1
- #define READ 0
- #define DEFAULT_LEN 70
- char temp[DEFAULT_LEN];
- int pdes[2];
- char str[50];
- void proces1p(){
- if(fork()==0)
- while(1){
- if(fgets(temp,DEFAULT_LEN,file)){
- file=fopen(str,"r");
- write(pdes[WRITE], temp, DEFAULT_LEN);
- fclose(file);
- }
- sleep(1);
- }
- }
- void proces1c(){
- if(fork()==0)
- //pid1=getpid();
- {
- while(1){
- char stri[100];
- fflush(stdin);
- usleep(1);
- gets(stri);
- write(pdes[WRITE], temp, DEFAULT_LEN);
- sleep(1);
- }
- fclose(file);
- }
- }
- void wybor(){
- char wyb;
- printf("podaj wybor");
- scanf("%c", &wyb);
- switch(wyb){
- case 'a':
- proces1c();
- break;
- case 'b':
- scanf("%s",str);
- file=fopen(str,"r");
- proces1p();
- break;
- }
- }
- void proces2(){
- char string[DEFAULT_LEN];
- int i;
- while(1){
- if (ioctl(pdes[0], FIONREAD, &i) != -1){
- read(pdes[READ],&string,DEFAULT_LEN);
- //i=strtol(string,NULL, 16);
- //i=atoi(string);
- printf("Odczytalem: %s\n", string);
- sleep(1);
- }
- }
- }
- void proces3(){
- }
- int main(int argc, char *argv[]){
- pipe(pdes);
- wybor();
- if(fork()==0){
- //pid2=getpid();
- proces2();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement