【Linux】管道简单使用模板

xiaoxiao2025-04-16  16

#include <unistd.h> #include <stdio.h> int main() { int fd[2]; int ret = pipe(fd); char readBuf[15]; if(ret < 0) perror("pipe(fd)"); pid_t pid = fork(); if(pid ==0) { close(fd[0]); write(fd[1],"hello 360\n",10); } else { close(fd[1]); read(fd[0],readBuf,10); printf("%s\n",readBuf); //sleep(1); } return 0; }

 

转载请注明原文地址: https://www.6miu.com/read-5028378.html

最新回复(0)