SemaphoreExamples

SemaphoreExamples - fileio1.c program #include...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
fileio1.c program  #include <fcntl.h> int fdrd, fdwt; char c; main(argc, argv)   int argc; char *argv[]; {   int PID;   if (argc !=3) {     printf("Usage: %s inputfile outfile\n", argv[0]);     exit(1);   }   PID = fork(); // child is created before opening/creating files   if((fdrd = open(argv[1], O_RDONLY)) == -1) exit (1);     exit(1);   rdwrt();   exit(0); } // of main rdwrt() {   for(;;)    {             return;      }      write(fdwt, &c, 1);    } // of for } // of rdwrt
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
fileio2.c program  #include <fcntl.h> int fdrd, fdwt; char c; main(argc, argv)   int argc; char *argv[]; {   int PID;   if (argc !=3) {     printf("Usage: %s inputfile outfile\n", argv[0]);     exit(1);   }   if((fdrd = open(argv[1], O_RDONLY)) == -1) exit (1);     exit(1);   PID = fork(); // child is created after files are opened/created   rdwrt();   exit(0); } // of main rdwrt() {   for(;;)    {             return;      }      write(fdwt, &c, 1);    } // of for } // of rdwrt
Background image of page 2
fileioS.c program  #include <sys/types.h> #include <sys/sem.h> #include <sys/ipc.h> #include <fcntl.h> int fdrd, fdwt, sid; char c; extern void P(); extern void V(); main(argc, argv)   int argc; char *argv[]; {   int PID;      sid = semget(IPC_PRIVATE, 1, IPC_CREAT|0666);   V(sid);   if (argc !=3) {     printf("Usage: %s inputfile outfile\n", argv[0]);     exit(1);   }   if((fdrd = open(argv[1], O_RDONLY)) == -1) exit (1);     exit(1);   PID = fork();   rdwrt();
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  exit(0); } // of main rdwrt() {   for(;;)    {       P(sid);            V(sid);            return;      }      write(fdwt, &c, 1);
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

SemaphoreExamples - fileio1.c program #include...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online