Design and Develop a program to copy standard i/p to standard o/p using asynchronous i/o.

AIM:

Design and Develop a program to copy standard i/p to standard o/p using asynchronous i/o.

Program:

#include<signal.h>
#include<fcntl.h>
#define BUFFSIZE 4096
int sigflag;
main()
{
   int n;
   char buff [BUFFSIZE];
   int sigio_func();
   signal (SIGIO,sigio_func();
   if (fcntl(0,F_SETDWN,getpid())<0)
      err-sys(“F_SETDWN,error”);
   if (fcntl(0,F_SETFL,FANC)<0)
      err-sys(“F_SETFL FASYNC,error”);
   for(;;)(sigblock(sigmask SIGIO));
   while(sigflag==0)
      sigpause 10)/* wait for a signal*/
   if(write(1,BUFF,N)!=N)
      err_sys(“write error”);
}
else if(n<0)
err_sys(“read error”);
else if(n==0)
exit 0; /*EOF*/
sig flag=0;/*turn off one flag*/
sigetmask(0);/* and receivable signal*/
}
int sigio func()
{
sigflag=1;/* just set flag and return */
}

Output:

Student@ubuntu:~$ gcc –o stadd.out stadd.c
Student@ubuntu:~$ ./stadd.out
I/O possible