求各位大佬帮忙,有可采纳答案 可以追加悬赏
需要用到这些系统函数完成
pid_t fork( void ); creates a child process that differs from the parent process only in terms of their process IDs.
int execlp( const char *file, const char *arg, ..., (char *)0 ); replaces the current process image with a new process image that will be loaded from file. The first argument arg must be the same as file.
int pipe( int filedes[2] ); creates a pair of file descriptors (which point to a pipe structure), and places them in the array pointed to by filedes. filedes[0] is for reading data from the pipe, filedes[1] is for writing data to the pipe.
int dup2( int oldfd, int newfd ); creates in newfd a copy of the file descriptor oldfd.
pid_t wait( int *status ); waits for process termination
int close( int fd ); closes a file descriptor.
只使用上面列出的系统调用。不要使用系统系统调用。模拟shell如何执行“ps -A | grep argv[1] | wc -l”。换句话说,您的父进程生成一个子进程,这个子进程生成一个曾孙进程,这个曾孙进程又生成一个曾孙进程。如下: