´ÙÀ½ À§·Î ÀÌÀü ¸ñÂ÷ ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å

6.3.3 FIFO µ¿ÀÛ (FIFO Operations)

FIFOÀÇ I/O µ¿ÀÛÀº ÇÑ°³ÀÇ ÁÖ¿äÇÑ Â÷ÀÌÁ¡À» Á¦¿ÜÇÏ°í º»ÁúÀûÀ¸·Î ÀÏ¹Ý ÆÄÀÌÇÁ¿Í °°´Ù. "open" ½Ã½ºÅÛ È£ÃâÀ̳ª ¶óÀ̺귯¸® ÇÔ¼ö´Â ¹°¸®ÀûÀ¸·Î ÆÄÀÌÇÁÀÇ Ã¤³ÎÀ» ¿©´Âµ¥ »ç¿ëµÇ¾îÁ®¾ß ÇÑ´Ù. ¹ÝÀÌÁß ÆÄÀÌÇÁ¿¡¼­´Â ÆÄÀÌÇÁ°¡ ¹°¸®ÀûÀÎ ÆÄÀÏ ½Ã½ºÅÛÀÌ ¾Æ´Ñ, Ä¿³Î¿¡ Á¸ÀçÇÔÀ¸·Î ºÒÇÊ¿äÇÏ´Ù. ¿¹Á¦¿¡¼­ ¿ì¸®´Â ÆÄÀÌÇÁ¸¦ fopen()À¸·Î ÆÄÀÏÀ» ¿­°í, fclose()·Î ´Ý´Â ½ºÆ®¸²(stream)ó·³ ´Ù·ê °Í ÀÌ´Ù.

°£´ÜÇÑ ¼­¹ö ÇÁ·Î¼¼½º¸¦ »ìÆ캸ÀÚ:

/*****************************************************************************
 ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å - 6Àå ¿¡¼­ ¹ßÃé
 (C)opyright 1994-1995, Scott Burkett
 ***************************************************************************** 
 MODULE: fifoserver.c
 *****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#include <linux/stat.h>

#define FIFO_FILE       "MYFIFO"

int main(void)
{
        FILE *fp;
        char readbuf[80];

	/*ÆÄÀÌÇÁ°¡ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é ¸¸µç´Ù*/
        umask(0);
        mknod(FIFO_FILE, S_IFIFO|0666, 0);

        while(1)
        {
                fp = fopen(FIFO_FILE, "r");
                fgets(readbuf, 80, fp);
                printf("Received string: %s\n", readbuf);
                fclose(fp);
        }

        return(0);
}
µðÆúÆ®·Î FIFO´Â Â÷´ÜµÊÀ¸·Î, ÄÄÆÄÀÏÇÑ ÈÄ¿¡ ¹é±×¶ó¿îµå·Î server¸¦ ½ÇÇà½ÃÄѶó:
        $ fifoserver&
Àá½Ã FIFOÀÇ Â÷´Ü µ¿ÀÛ¿¡ ´ëÇØ ¸»ÇÏ°Ú´Ù. ¸ÕÀú, ¼­¹ö¿¡ ´ëÇÑ ´ÙÀ½ÀÇ °£´ÜÇÑ Å¬¶óÀ̾ðÆ® º¯È¯ºÎ(frontend)¸¦ »ìÆ캸ÀÚ:
/*****************************************************************************
 ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å - 6Àå ¿¡¼­ ¹ßÃé
 (C)opyright 1994-1995, Scott Burkett
 ***************************************************************************** 
 MODULE: fifoclient.c
 *****************************************************************************/

#include <stdio.h>
#include <stdlib.h>

#define FIFO_FILE       "MYFIFO"

int main(int argc, char *argv[])
{
        FILE *fp;

        if ( argc != 2 ) {
                printf("USAGE: fifoclient [string]\n");
                exit(1);
        }

        if((fp = fopen(FIFO_FILE, "w")) == NULL) {
                perror("fopen");
                exit(1);
        }

        fputs(argv[1], fp);

        fclose(fp);
        return(0);
}


ÀÌÀü:6.3.2 FIFO ¸¸µé±â ´ÙÀ½:6.3.4 FIFOÀÇ µ¿ÀÛ Â÷´Ü

Copyright (c) 1996,1997 by Euibeom.Hwang & SangEun.Oh All Rights Reserved

Email To:Webmaster , Another address
LAST UPDATE Nov 15,1997
Created Nov 15,1997