ВУЗ:
Составители:
270
#include <strings.h>
#include <fstream.h>
#include <sys/stat.h>
#include <errno.h>
#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;
Страницы
- « первая
- ‹ предыдущая
- …
- 268
- 269
- 270
- 271
- 272
- …
- следующая ›
- последняя »