mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 19:36:47 +00:00
* 更改编译器的Include路径,使得include时不需要加`<libc/src/include/>`前缀 * 修改include路径 Co-authored-by: longjin <longjin@RinGoTek.cn>
32 lines
665 B
C
32 lines
665 B
C
#include "cmd_test.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
int shell_pipe_test(int argc, char **argv)
|
|
{
|
|
int ret = -1;
|
|
int fd[2];
|
|
pid_t pid;
|
|
char buf[512] = {0};
|
|
char *msg = "hello world";
|
|
|
|
ret = pipe(fd);
|
|
if (-1 == ret) {
|
|
printf("failed to create pipe\n");
|
|
return -1;
|
|
}
|
|
pid = fork();
|
|
if (0 == pid) {
|
|
// close(fd[0]);
|
|
ret = write(fd[1], msg, strlen(msg));
|
|
exit(0);
|
|
} else {
|
|
// close(fd[1]);
|
|
ret = read(fd[0], buf, sizeof(buf));
|
|
printf("parent read %d bytes data: %s\n", ret, buf);
|
|
}
|
|
|
|
return 0;
|
|
} |