/
githubmirror
/
lsof
Обзор
Документация
Войти
/
githubmirror
/
lsof
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/dialects/linux/tests/pipe.c
41 строка
726 B
Jiajie Chen
Change folder structure for library changes:
27 мар 2023, 14:44
27 мар 2023, 14:44
439f90c
Код
Авторство
О чём код?
#include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <string.h> int main(int argc, char **argv) { int no_close = 0; if (argc > 1 && strcmp(argv[1], "no-close") == 0) no_close = 1; int pd[2]; if (pipe(pd) < 0) { perror("pipe"); return 1; } pid_t self, child; self = getpid(); child = fork(); if (child == 0) { if (!no_close) close(pd[0]); pause(); return 0; } else if (child < 0) { perror("fork"); return 1; } if (!no_close) close(pd[1]); printf("%d %d %d %d\n", self, child, pd[0], pd[1]); fflush(stdout); wait(NULL); return 0; }