//unnamed pipe
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *s="I am a message";
main(){
int fd[2];
int bytesread;
char buf[100];
pipe(fd);
if(fork()==0){
close(fd[0]);
write(fd[1],s,strlen(s));
close(fd[1]);
}
else{
close(fd[1]);
bytesread=read(fd[0],buf,100);
printf("%s,%d \n",buf,bytesread);
close(fd[0]);
}
}
//named pipe , writer program
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
char *s="I am a message XD !";
int main(int argc,char *argv[]){
int r,w;
if(argc!=2){printf("errore: inserire il nome della pipe\n");exit(1);}
if((mknod(argv[1],S_IFIFO|0666,0)==-1)&&(errno != EEXIST)){
perror("errore mknod");exit(1);
}
if((w=open(argv[1],O_WRONLY)==-1)){perror("errore open");exit(-1);}
if((write(w,s,strlen(s)+1))==-1){perror("errore write");exit(-1);}
close(w);
}
//unnamed pipe, reader program
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
char *s="I am a message XD !!";
int main(int argc, char *argv[]){
char buf[100];
int bytesread;
int r,w;
if(argc!=2){printf("manca l'argomento\n");exit(1);}
if(mknod(argv[1],S_IFIFO|0666,0)==-1){perror("errore nella creazione");exit(1);}
if(r=open(argv[1],O_RDONLY)==-1){perror("errore nell'apertura");exit(1);}
if((bytesread=read(r,buf,100))==-1){perror("errore nella lettura");exit(1);}
printf("%s,%d\n",buf,bytesread);
close(r);
}
mercoledì 17 febbraio 2010
Iscriviti a:
Commenti sul post (Atom)
How to deploy Podman images to OpenShift Container Platform (CRC on localhost)
I have a microservice on localhost and I want to deploy its Podman image on OCP, which I am running using CRC on localhost. 1. Get the...
-
Precondizione: La precondizione di un metodo e' una condizione che deve essere verificata prima che quel metodo sia invocato. Le preco...
-
My intent is to configure SSO on Keycloak and Liferay. I have createad a docker-compose environment with Keycloak: #####################...
Nessun commento:
Posta un commento