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

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

.c
Скачиваний:
40
Добавлен:
17.04.2013
Размер:
1.03 Кб
Скачать
/* Named pipe: a server program */
/* Usage: progname pipename & */

#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];

    /*
     * Remove any previous FIFO.
     */
    unlink(argv[1]);

    /*
     * Create the FIFO.
     */
    if (mkfifo(argv[1], 0666) < 0) {
        perror("mkfifo");
        exit(1);
    }

    /* Make sure that the mode of the pipe is really 0666 */
    if(chmod(argv[1], 0666) < 0) {perror("chmod"); exit(1);}

    /*
     * Open the FIFO for reading.
     * The server will block here until the client starts...
     */
    if ((fd = open(argv[1], O_RDONLY)) < 0) {
        perror("open");
        exit(1);
    }

    /*
     * Read from the FIFO until end-of-file and
     * print what we get on the standard output.
     */
    while ((n = read(fd, buf, sizeof(buf))) > 0)
        write(1, buf, n);

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