Lecture11 - CSCE 313 Introduction to Computer Systems...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSCE 313 Introduction to Computer Systems Instructor: Dr. Ronnie Ward Based on material from Dr. Guofei Gu UNIX Special Files Pipes Named Pipes (FIFOs) Client/Server model Special Files and Devices Reading: R&R, Ch 6, Sections 1-4 3/23/2011 #include <unistd.h> int pipe (int fildes[2]); /* fildes[0] for reading, fildes[1] for writing */ Pipes pipe fildes[0] fildes[1] #include <stio.h> #include <unistd.h> int main(int argc, char ** argv) { int fd[2]; char result[MAX_LENGTH]; pipe(fd); if (fork()) fprintf(fd[1], I am writing into the pipe\n); else { fscanf(fd[0], %s, result); printf(I read <%s> from the pipe.\n, result); } } Use Pipes for Synchronization Example: Barrier Synchronization using Pipes: int main(int argc, char ** argv) { int fd[2]; n = atoi(argv[1]); pipe(fd); for (int i=1; i<n; i++) /* start children */ if ((childpid = fork()) <= 0) break; if (childpid > 0) { /* parent writes synch characters into pipe */ for (int j=0; j<n; j++) write(fd[1], g, 1); } read(fd[0], buf, 1); /* everybody synchronizes here */ } Pipeline Example #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> void main(void) { int fd[2];...
View Full Document

Page1 / 11

Lecture11 - CSCE 313 Introduction to Computer Systems...

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

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