ВУЗ:
Составители:
111
#include <fcntl.h>
#define MAXLINE 128
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
#define FIFO1 “/tmp/fifo.1”
#define FIFO2 “/tmp/fifo.2”
int main(int argc, char **argv) {
int readfd = -1,writefd = -1;
pid_t childpid = 0;
ssize_t n;
char str[MAXLINE];
strcpy(str," some string to transmit ");
cout<<"Creating pipes..."<<endl;
unlink(FIFO1);
unlink(FIFO2);
if (mkfifo(FIFO1, FILE_MODE) == EEXIST) cout<<"\n Pipes is ex-
ists"<<endl;
if (mkfifo(FIFO2, FILE_MODE) == EEXIST) cout<<"\n Pipes is ex-
ists"<<endl;
cout<<"Pipes created..."<<endl;
writefd = open(FIFO2, O_WRONLY);
if ((writefd != -1)) {
cout<<"Transmitting the string..."<<endl;
write(writefd,str,strlen(str));
readfd = open(FIFO1, O_RDONLY);
cout<<"Waiting for respond..."<<endl;
while ((n = read(readfd,str, MAXLINE)) > 0) {
str[n] = 0;
cout<<"Received string - \""<<str<<"\""<<endl;
break;
}
close(readfd);
close(writefd);
unlink(FIFO1);
Страницы
- « первая
- ‹ предыдущая
- …
- 109
- 110
- 111
- 112
- 113
- …
- следующая ›
- последняя »
