Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы(ОС) / Lab6 / client

.c
Скачиваний:
40
Добавлен:
17.04.2013
Размер:
791 б
Скачать
/* Named pipe: a client program */
/* Usage: progname pipename */
/*    or: progname pipename < text-file */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* #define FIFONAME    "myfifo" */

int
main(int argc, char * argv[])

{
    int n, fd;
    char buf[1024];

    /*
     * Open the pipe for writing.  It was
     * created by the server already.
     */
    if ((fd = open(argv[1], O_WRONLY)) < 0) {
        perror("open");
        exit(1);
    }

    /*
     * Read from standard input, and copy the
     * data to the pipe.
     * If data is input from the keyboard 
     * then terminate input by double CTRL/D
     */
    while ((n = read(0, buf, sizeof(buf))) > 0)
        write(fd, buf, n);

    close(fd);
    exit(0);
}
Соседние файлы в папке Lab6