Vous êtes sur la page 1sur 11

//append data in file from another file id=fork();

#include<fcntl.h> if(id==0)
main() {
{ printf("child pid is %d \n",getpid());
int fd1,fd2,n; printf("parent id is %d \n",getppid());
char b[1024]; exit(0);
fd1=open("f1",O_RDONLY); }
fd2=open("f2",O_WRONLY | O_APPEND); else{
while((n=read(fd1,b,1024))>0) printf("child pid is %d \n",id);
write(fd2,b,n); printf("main process id %d \n",getpid());
close(fd1); }
close(fd2); exit(0);
} }
}
//display file contents by giving file
name by command line argument //copy from one file to another
#include<fcntl.h> #include<fcntl.h>
main (int argc,char **argv) main()
{ {
int f1,f2,n,i; int fd1,fd2,n;
char b[1024]; char buffer[1024];
for(i=1;i<argc;i++) fd1=open("f1",O_CREAT |
{ O_RDONLY,0777);
f1=open(argv[i],O_RDONLY); fd2=open("f2",O_CREAT |O_WRONLY,0777);
//f2=open(argv[2],O_RDONLY); while((n=read(fd1,buffer,1024))>0)
while((n=read(f1,b,1024))>0) write(fd2,buffer,n);
write(1,b,n); close(fd1);
} close(fd2);
close(f1); }
close(f2);
} //copy contents of one file to another
taking file name by command line
//append data in file from another file argument
#include<fcntl.h> #include<fcntl.h>
main() main(int argc,char **argv)
{ {
int fd1,fd2,n; int f1,n,f2;
char b[1024]; char b[1024];
fd1=open("f1",O_RDONLY); f1=open(argv[1],O_RDONLY);
fd2=open("f2",O_WRONLY | O_APPEND); f2=open(argv[2],O_RDONLY);
while((n=read(fd1,b,1024))>0) while((n=read(f1,b,1024))>0)
write(fd2,b,n); write(f2,b,1024);
close(fd1); close(f1);
close(fd2); close(f2);
} }

//display parent and child ID's //to know the file size by using l_seek
#include<fcntl.h> #include<fcntl.h>
main() main()
{ {
int id,i; int fd,n;
for(i=1;i<=3;i++) char b[1024];
{ fd=open("f1",O_RDONLY);
n=lseek(fd,0,2); }
printf("%d \n",n);
/*while((n=read(fd,b,1024))>0) // excute command $ wc < f2
write(1,b,n);*/ #include<fcntl.h>
} main()
{
//execute ls command int fd;
#include<fcntl.h> fd=open("f1",O_RDONLY);
main() close(0);
{ dup(fd);
int id,fd; execlp("wc","wc",0);
id=fork(); }
if(id==0)
{ // command wc >f1 <f3
close(1); #include<fcntl.h>
fd=open("f2",O_WRONLY); main()
execl("/bin/ls","ls",0); {
} int fd1,fd2,id;
else fd1=open("f1",O_RDONLY);
wait(); fd2=open("f3",O_WRONLY);
} close(0);
dup(fd1);
//copy file contents using fork close(1);
#include<fcntl.h> dup(fd2);
main() execlp("wc","wc",0);
{ }
int fd1;
fd1=fork(); //client-server program by using fifo
if(fd1==0) #include<fcntl.h>
{ #include<sys/types.h>
execl("/bin/cp","cp","ls_pgm.c","dup_pgm.c" #include<sys/stat.h>
,0); #include<stdio.h>
} void server(int , int ), client (int , int );
else{ main()
wait(); {
} int id,rfd,wfd;
} mkfifo("fifo1",S_IRUSR | S_IWUSR);
mkfifo("fifo2",S_IRUSR | S_IWUSR);
// executing ls >f1 command id=fork();
#include<fcntl.h> if(id==0)
main() {
{ rfd=open("fifo1",O_RDONLY,0);
int id,fd; wfd=open("fifo2",O_WRONLY,0);
id=fork(); server(rfd,wfd);
if(id==0) }
{ else{
fd=open("f1",O_WRONLY); wfd=open("fifo1",O_WRONLY,0);
close(1); rfd=open("fifo2",O_RDONLY,0);
dup(fd); client(rfd,wfd);
execl("/bin/ls","ls",0); }
} }
else void client(int r, int w)
wait(); {
char buff[1024]; if(id==0)
int n,fd; {
fgets(buff,1024, stdin); execl("/bin/ls","ls",0);
//n=read(0,buff,1024); }
n=strlen(buff); else{
buff[n-1]=0; execlp("ls","ls","-l",0);
write(w,buff,n); }
while((n=read(r,buff,1024))>0) }
write(1,buff,n);
} //echo + if file name is given by user
void server(int r1,int w1) then it will display contents of that
{ file in monitor, there may be more than
char buff[1024]; one file name can be given by the user
int n,fd; #include<fcntl.h>
n=read(r1,buff,1024); main(int argc, char **argv)
fd=open(buff,O_RDONLY); {
while((n=read(fd,buff,1024))>0) int i,f1,f2,n;
{ char b[1024];
write(w1,buff,n); if(argc==1)
} {
} while((n=read(0,b,1024))>0)
write(1,b,n);
//changing group of processes having }
pid even else
#include<fcntl.h> {
main() for(i=1;i<argc;i++)
{ {
int i,id; f1=open(argv[i],O_RDONLY);
//setpgrp(); while((n=read(f1,b,1024))>0)
for(i=0;i<10;i++) write(1,b,n);
{ }
id = fork(); }
if(id==0) //close(f1);
{ }
if(i%2==0)
setpgrp(); //display content of file in reverse
printf("pid and pgrpid are %d and %d #include<fcntl.h>
\n",getpid(),getpgrp()); main(int argc, char **argv)
pause(); {
} int fd,n,p,fd1,z,i;
} char b;
kill(0,-9); fd=open(argv[1],O_RDONLY);
} fd1=open(argv[2],O_CREAT |
O_WRONLY,0777);
// execute ls and ls -l command and z=lseek(fd,2,2);
result will store in file f4 for(i=1;i<z;i++)
#include<fcntl.h> {
main() read(fd,&b,1);
{ write(fd1,&b,1);
int fd1,id; lseek(fd,-i,2);
id=fork(); }
close(1); }
fd1=open("f4",O_WRONLY|O_APPEND);
//reverse of file }
#include<fcntl.h>
main() //client server pgm using by pipe
{ #include<fcntl.h>
int fd,n,p,fd1,z,i; #include<string.h>
char b; #include<stdio.h>
fd=open("f1",O_RDONLY); void client(int ,int ), server(int ,int );
fd1=open("f2",O_CREAT | main()
O_WRONLY,0777); {
z=lseek(fd,0,2); int p1[2],p2[2],id;
for(i=1;i<=z;i++) pipe(p1);
{ pipe(p2);
lseek(fd,-i,2); id=fork();
read(fd,&b,1); if(id==0)
write(fd1,&b,1); {
} close(p1[1]);
} close(p2[0]);
server(p1[0],p2[1]);
//display content of file in reverse exit(0);
#include<fcntl.h> }
main(int argc, char **argv) else
{ {
int fd,n,p,fd1,z,i=0; close(p1[0]);
char b; close(p2[1]);
fd=open(argv[1],O_RDONLY); client(p2[0],p1[1]);
fd1=open(argv[2],O_WRONLY | waitpid(id,0,0);
O_CREAT,0777); exit(0);
z=lseek(fd,0,2); }
while(++i <= z) }
{ void client(int r, int w)
lseek(fd,-i,2); {
read(fd,&b,1); char buff[1024];
write(fd1,&b,1); int n,fd;
} fgets(buff,1024,stdin);
} //n=read(0,buff,1024);
n=strlen(buff);
//signal handler buff[n-1]=0;
#include<fcntl.h> write(w,buff,n);
#include<signal.h> while((n=read(r,buff,1024))>0)
void catch(int ); write(1,buff,n);
main() }
{ void server(int r,int w)
signal(SIGQUIT,catch); {
signal(SIGINT,catch); char buff[1024];
for( ; ; ) int n,fd;
pause(); n=read(r,buff,1024);
} fd=open(buff,O_RDONLY);
void catch(int signo) while((n=read(fd,buff,1024))>0)
{ write(w,buff,n);
if(signo==SIGINT) }
printf("inturrupt signal \n");
else if (signo==SIGQUIT) // command ls | sort
printf("quit signal \n"); #include<fcntl.h>
main() {
{ close(0);
int pfd[2],id; dup(pfd[0]);
pipe(pfd); close(pfd[0]);
id=fork(); close(pfd[1]);
if(id==0) }
{ }
close(1);
dup(pfd[1]); //command ls | sort | wc
execlp("ls","ls",0); #include<fcntl.h>
} main()
else {
{ int pfd[2],pfd1[2],id,id1;
close(0); pipe(pfd);
dup(pfd[0]); id=fork();
close(pfd[1]); if(id==0)
execlp("sort","sort",0); {
} pipe(pfd1);
} id1=fork();
if(id1==0)
// command ls | sort using dup {
#include<fcntl.h> close(1);
main() dup(pfd1[1]);
{ close(pfd1[0]);
int pfd[2],pfd2[2],id,id1; close(pfd1[1]);
pipe(pfd); execlp("ls","ls",0);
id=fork(); }
if(id==0) else
{ {
pipe(pfd1); close(0);
id1=fork(); dup(pfd1[0]);
if (id1==0) close(pfd1[0]);
{ close(pfd1[1]);
close(1); close(1);
dup(pfd1[1]); dup(pfd[1]);
close(pfd1[0]); close(pfd[0]);
close(pfd1[1]); close(pfd[1]);
execlp("ls","ls",0); execlp("sort","sort",0);
exit(0); }
} }
else else {
{ close(0);
close(0); dup(pfd[0]);
dup(pfd1[0]); //close(pfd[1]);
close(pfd1[0]); close(pfd[0]);
close(1); execlp("wc","wc",0);
dup(pfd[1]); }
close(pfd[1]); }
execlp("sort","sort",0);
exit(0); // ls| sort | wc using dup
} #include<fcntl.h>
} main()
else {
int p[2],p1[2],i1,i2; {
pipe(p); close(1);
i1=fork(); dup(p1[1]);
if(i1==0) close(p1[1]);
{ close(p1[0]);
pipe(p1); close(p[0]);
i2=fork(); close(p[1]);
if(i2==0) execlp("ls","ls",0);
{ }
close(1); else
dup(p1[1]); {
close(p1[1]); close(0);
close(p1[0]); dup(p1[0]);
close(p[0]); close(p1[0]);
close(p[1]); close(p1[1]);
execlp("ls","ls",0); close(1);
} dup(p[1]);
else close(p[1]);
{ close(p[0]);
close(0); execlp("sort","sort",0);
dup(p1[0]); exit(0);
close(p1[0]); }
close(p1[1]); }
close(1); else
dup(p[1]); {
close(p[1]); close(0);
close(p[0]); dup(p[0]);
execlp("sort","sort",0); close(p[0]);
exit(0); f1=open("file1",O_CREAT |
} O_WRONLY,0777);
} close(1);
else iclose(p[1]);
{ dup(f1);
close(0); close(f1);
dup(p[0]); execlp("wc","wc",0);
close(p[0]); }
close(p[1]); }
execlp("wc","wc",0);
} // daytime server using TCP connection
} #include<time.h>
#include<stdio.h>
// program $ ls | sort |wc > file1 #include<sys/socket.h>
#include<fcntl.h> #include<netinet/in.h>
main() #include<stdlib.h>
{ main(int argc,char **argv)
int p[2],p1[2],i1,i2,f1; {
pipe(p); int lfd,cfd,n,fd,len;
i1=fork(); char b[1024];
if(i1==0) struct sockaddr_in serv, cli;
{ time_t ticks;
pipe(p1); lfd=socket(AF_INET,SOCK_STREAM,0);
i2=fork(); serv.sin_family=AF_INET;
if(i2==0) serv.sin_port=htons(1900);
serv.sin_addr.s_addr=htonl(0);; char b[1024];
if((bind(lfd,(struct sockaddr struct sockaddr_in serv;
*)&serv,sizeof(serv)))<0) lfd=socket(AF_INET,SOCK_STREAM,0);
printf("bind error \n"); serv.sin_family=AF_INET;
listen(lfd,5); serv.sin_port=htons(13421);
for(;;) serv.sin_addr.s_addr=htonl(0);
{ if((bind(lfd,(struct sockaddr
if((cfd=accept(lfd,(struct sockaddr *)&serv,sizeof(serv)))<0)
*)&cli,&len))<0) printf("bind error \n");
printf("connet error\n"); listen(lfd,5);
ticks=time(NULL); for(;;)
snprintf(b,sizeof(b),"%s\n",ctime(&ticks)); {
write(cfd,b,strlen(b)); cfd=accept(lfd,(struct sockaddr
close(cfd); *)NULL,NULL);
//exit(0); while((n=read(cfd,b,1024))>0)
} write(cfd,b,n);
} close(cfd);
}
// TCP daytime client }
#include<sys/socket.h>
#include<netinet/in.h> //TCP echo client
#include<stdio.h> #include<sys/socket.h>
#include<stdlib.h> #include<netinet/in.h>
main(int argc,char **argv) #include<fcntl.h>
{ main(int argc, char **argv )
int sfd,n; {
char b[1024]; int n,sfd;
struct sockaddr_in serv; char b[1024];
if((sfd=socket(AF_INET,SOCK_STREAM,0))< struct sockaddr_in serv;
0) if((sfd=socket(AF_INET,SOCK_STREAM,0))<
printf("socket error \n"); 0)
//bzero(&serv,sizeof(serv)); printf("socket erroe\n");
serv.sin_family=AF_INET; serv.sin_family=AF_INET;
serv.sin_port=htons(1900); serv.sin_port=htons(13421);
//serv.sin_addr.s_addr=htonl(0); //serv.sin_addr.s_addr=htonl(0);
if((inet_pton(AF_INET,argv[1],&serv.sin_add if((inet_pton(AF_INET,argv[1],&serv.sin_add
r))<=0) r))<=0)
printf("inet p_ton error %s\n",argv[1]); printf("iton error\n");
if((connect(sfd,(struct sockaddr if((connect(sfd,(struct sockaddr
*)&serv,sizeof(serv)))<0) *)&serv,sizeof(serv)))<0)
printf("connect error\n"); printf("connect error\n");
n=read(sfd,b,1024); while((n=read(0,b,1024))>0)
write(1,b,n); {
close(sfd); write(sfd,b,n);
} n=read(sfd,b,1024);
write(1,b,n);
//TCP echo server }
#include<sys/socket.h> close(sfd);
#include<netinet/in.h> }
#include<fcntl.h>
main() //TCP file server
{ #include<fcntl.h>
int lfd,cfd,n; #include<sys/socket.h>
#include<netinet/in.h> printf("connet error\n");
#include<stdio.h> n=read(cfd,b,1024);
main(int argc,char **argv) b[n-1]=0;
{ fd=open(b,O_RDONLY);
int sfd,n,portno; while((n=read(fd,b,1024))>0)
char b[1024]; write(cfd,b,n);
struct sockaddr_in serv; close(cfd);
//portno=atoi(argv[2]); }
sfd=socket(AF_INET,SOCK_STREAM,0); }
if(sfd<0)
printf("Socket error\n"); //UDP echo serevr
serv.sin_family=AF_INET; #include<netinet/in.h>
serv.sin_port=htons(5678); #include<sys/socket.h>
serv.sin_addr.s_addr=htonl(0); #include<fcntl.h>
if((inet_pton(AF_INET,argv[1],&serv.sin_add main()
r))<=0) {
printf("inet_ptons %s\n",argv[1]); int lfd,cfd,n,len;
if((connect(sfd,(struct sockaddr char b[1024];
*)&serv,sizeof(serv)))<0) struct sockaddr_in serv,cli;
printf("connect error\n"); lfd=socket(AF_INET,SOCK_DGRAM,0);
fgets(b,1024,stdin); serv.sin_family=AF_INET;
write(sfd,b,strlen(b)); serv.sin_port=htons(16321);
while((n=read(sfd,b,1024))>0) serv.sin_addr.s_addr=htonl(0);
write(1,b,n); if((bind(lfd,(struct sockaddr
} *)&serv,sizeof(serv)))<0)
printf("bind error \n");
//TCP file server len=sizeof(cli);
#include<fcntl.h> for(;;)
#include<stdio.h> {
#include<sys/socket.h> n=recvfrom(lfd,b,1024,0,(struct sockaddr
#include<netinet/in.h> *)&cli,&len);
#include<signal.h> //while((n=read(cfd,b,1024))>0)
void catch(int ); sendto(lfd,b,n,0,(struct sockaddr *)&cli,len);
main() }
{ close(cfd);
int lfd,cfd,n,fd,len; }
char b[1024];
struct sockaddr_in serv, cli; //udp echo client
if((lfd=socket(AF_INET,SOCK_STREAM,0))< #include<fcntl.h>
0) #include<netinet/in.h>
printf("socket erroe\n"); #include<stdio.h>
serv.sin_family=AF_INET; #include<sys/socket.h>
serv.sin_port=htons(9157); main(int argc, char **argv )
serv.sin_addr.s_addr=htonl(0);; {
if((bind(lfd,(struct sockaddr int n,sfd,len;
*)&serv,sizeof(serv)))<0) char b[1024];
printf("bind error \n"); struct sockaddr_in serv,cli;
listen(lfd,5); if((sfd=socket(AF_INET,SOCK_DGRAM,0))<0
len=sizeof(cli); )
for(;;) printf("socket error\n");
{ serv.sin_family=AF_INET;
if((cfd=accept(lfd,(struct sockaddr serv.sin_port=htons(16321);
*)&cli,&len))<0) //serv.sin_addr.s_addr=htonl(0);
if((inet_pton(AF_INET,argv[1],&serv.sin_add int lfd,cfd,n,fd,len;
r))<=0) char b[1024];
printf("iton error\n"); struct sockaddr_in serv, cli;
len=sizeof(cli); time_t ticks;
while((n=read(0,b,1024))>0) if((lfd=socket(AF_INET,SOCK_STREAM,0))<
{ 0)
sendto(sfd,b,n,0,(struct sockaddr printf("socket error\n");;
*)&serv,sizeof(serv)); serv.sin_family=AF_INET;
n=recvfrom(sfd,b,1024,0,(struct sockaddr serv.sin_port=htons(1900);
*)&cli,&len);//NULL,NULL); serv.sin_addr.s_addr=htonl(0);;
write(1,b,n); if((bind(lfd,(struct sockaddr
} *)&serv,sizeof(serv)))<0)
} printf("bind error \n");
listen(lfd,5);
// UDP day time program client for(;;)
#include<sys/socket.h> {
#include<netinet/in.h> if((cfd=accept(lfd,(struct sockaddr
#include<stdio.h> *)&cli,&len))<0)
#include<stdlib.h> printf("connet error\n");
main(int argc,char **argv) ticks=time(NULL);
{ snprintf(b,sizeof(b),"%.24s\r\n",ctime(&ticks
int sfd,n; ));
char b[1024]; write(cfd,b,strlen(b));
struct sockaddr_in serv; close(cfd);
if((sfd=socket(AF_INET,SOCK_STREAM,0))< exit(0);
0) }
printf("socket error \n"); }
bzero(&serv,sizeof(serv));
serv.sin_family=AF_INET; // UDP file server client
serv.sin_port=htons(1900); #include<fcntl.h>
//serv.sin_addr.s_addr=htonl(0); #include<stdio.h>
if((inet_pton(AF_INET,argv[1],&serv.sin_add #include<sys/socket.h>
r))<=0) #include<netinet/in.h>
printf("inet p_ton error %s\n",argv[1]); main(int argc, char **argv )
if((connect(sfd,(struct sockaddr {
*)&serv,sizeof(serv)))<0) int n,sfd,len;
printf("connect error\n"); char b[1024];
while((n=read(sfd,b,1024))>0) struct sockaddr_in serv,cli;
{ if((sfd=socket(AF_INET,SOCK_DGRAM,0))<0
b[n-1]=0; )
fputs(b,stdout); printf("socket error\n");
} serv.sin_family=AF_INET;
exit(0); serv.sin_port=htons(12340);
} //serv.sin_addr.s_addr=htonl(0);
inet_pton(AF_INET,argv[1],&serv.sin_addr);
// UDP day time program server len=sizeof(cli);
#include<time.h> fgets(b,1024,stdin);
#include<stdio.h> sendto(sfd,b,strlen(b),0,(struct sockaddr
#include<sys/socket.h> *)&serv,sizeof(serv));
#include<netinet/in.h> //write(sfd,b,strlen(b));
#include<stdlib.h> n=recvfrom(sfd,b,1024,0,(struct sockaddr
main(int argc,char **argv) *)&cli,&len);
{ write(1,b,n);
close(sfd); if((sfd=socket(AF_INET,SOCK_STREAM,0))<
//fputs(b,stdout); 0)
//sendto(1,b,1024,0,(struct sockaddr printf("socket erroe\n");
*)&serv,sizeof(serv)); serv.sin_family=AF_INET;
} serv.sin_port=htons(13321);
//serv.sin_addr.s_addr=htonl(0);
if((inet_pton(AF_INET,argv[1],&serv.sin_add
//UDP file server server r))<=0)
#include<fcntl.h> printf("iton error\n");
#include<sys/socket.h> if((connect(sfd,(struct sockaddr
#include<netinet/in.h> *)&serv,sizeof(serv)))<0)
main(int argc,char **argv) printf("connect error\n");
{ while((n=read(0,b,1024))>0)
int lfd,cfd,n,fd,len,portno; {
char b[1024]; write(sfd,b,n);
struct sockaddr_in serv,cli; n=read(sfd,b,1024);
//portno=atoi(argv[1]); write(1,b,n);
lfd=socket(AF_INET,SOCK_DGRAM,0); }
serv.sin_family=AF_INET; close(sfd);
serv.sin_port=htons(12340);//(portno); }
serv.sin_addr.s_addr=htonl(0);
if((bind(lfd,(struct sockaddr //TCP echo concurrent server
*)&serv,sizeof(serv)))<0) #include<sys/socket.h>
printf("bind error \n"); #include<netinet/in.h>
listen(lfd,5); #include<fcntl.h>
len=sizeof(cli); #include<signal.h>
for(;;) void catch(int);
{ main()
n=recvfrom(lfd,b,1024,0,(struct sockaddr {
*)&cli,&len); int lfd,cfd,n,id;
//sendto(lfd,b,n,0,(struct sockaddr char b[1024];
*)&cli,len); struct sockaddr_in serv;
//n=read(lfd,b,1024); signal(SIGCHLD,catch);
b[n-1]=0; if((lfd=socket(AF_INET,SOCK_STREAM,0))<
fd=open(b,O_RDONLY); 0)
//n=recvfrom(fd,b,1024,0,(struct sockaddr printf("socket erro \n");
*)&cli,&len); serv.sin_family=AF_INET;
while((n=read(fd,b,1024))>0) serv.sin_port=htons(13321);
sendto(lfd,b,n,0,(struct sockaddr *)&cli,len); serv.sin_addr.s_addr=htonl(0);
//write(lfd,b,n); if((bind(lfd,(struct sockaddr
close(lfd); *)&serv,sizeof(serv)))<0)
} printf("bind error \n");
} listen(lfd,5);
for(;;)
//Echo concurrent client {
#include<sys/socket.h> if((cfd=accept(lfd,(struct sockaddr
#include<netinet/in.h> *)NULL,NULL))<0)
#include<fcntl.h> printf("error in connection\n");
main(int argc, char **argv ) id=fork();
{ if(id==0)
int n,sfd; {
char b[1024]; close(lfd);
struct sockaddr_in serv; while((n=read(cfd,b,1024))>0)
write(cfd,b,n); exit(0);
exit(0); }
} close(cfd);
close(cfd); }
} }
} void catch(int signo)
void catch(int signo) {
{ if(signo==SIGCHLD)
if(signo==SIGCHLD) waitpid();
waitpid(); wait(0);
wait(0); }
}
//RPC Client
//TCP concurrent file server #include<fcntl.h>
#include<fcntl.h> #include "square.h"
#include<stdio.h> main(int argc, char **argv)
#include<sys/socket.h> {
#include<netinet/in.h> CLIENT *cl;
#include<signal.h> square_out *outp;
void catch(int ); square_in in;
main(int argc, char **argv) cl=clnt_create(argv[1], SQUARE_PROG,
{ SQUARE_VERS, "tcp");
int lfd,cfd,n,fd,len,id,portno; in.arg1=atol(argv[2]);
char b[1024]; outp=squareproc_1(&in, cl);
struct sockaddr_in serv, cli; printf("%ld", outp->res1);
signal(SIGCHLD,catch); }
//portno=atoi(argv[1]);
if((lfd=socket(AF_INET,SOCK_STREAM,0))< //RPC Server
0) #include "square.h"
printf("socket error\n"); square_out *squareproc_1_svc(square_in
serv.sin_family=AF_INET; *inp, struct svc_req *rqstp)
serv.sin_port=htons(5678); {
serv.sin_addr.s_addr=htonl(0);; static square_out out;
if((bind(lfd,(struct sockaddr out.res1 = inp->arg1*inp->arg1;
*)&serv,sizeof(serv)))<0) return (&out);
printf("bind error \n"); }
listen(lfd,5);
len=sizeof(cli); //Square.x
for(;;) struct square_in
{ {
if((cfd=accept(lfd,(struct sockaddr long arg1;
*)&cli,&len))<0) };
printf("connet error\n"); struct square_out
id=fork(); {
if(id==0) long res1;
{ };
close(lfd); program SQUARE_PROG
n=read(cfd,b,1024); {
b[n-1]=0; version SQUARE_VERS
fd=open(b,O_RDONLY); {
while((n=read(fd,b,1024))>0) square_out SQUAREPROC(square_in) = 1;
write(cfd,b,n); } = 1;
close(cfd); } = 0x34560110;

Vous aimerez peut-être aussi