linux编程 设计myshell,在myshell里追加pipe功能

来源:百度知道 编辑:UC知道 时间:2024/05/30 02:20:12
如题,设计myshell

使myshell里有pipe的功能

请给出足够的注释,能让我看明白一点的

谢谢

/* smallsh.h */

#include

#define EOL 1
#define ARG 2
#define AMPERSAND 3
#define SEMICOLON 4
#define MAXARG 512
#define MAXBUF 512
#define FOREGROUND 0
#define BACKGROUND 1

/* smallsh.c - simple command procedure
as described in Haviland & Salama,
UNIX System Programming */

#include "smallsh.h"

char *prompt = "Myprog>";

main()
{
while (userin(prompt) != EOF)
procline();
}

/* runcommand.c */
#include "smallsh.h"

/* execute a command with optional wait */

runcommand (cline, where)
char **cline;
int where;
{

int pid, exitstat, ret;

if ((pid = fork()) < 0)
{
perror ("smallsh");
return (-1);
}

if (pid == 0) /* child */
{
execvp (*cline, cline);
perror (*cline);
exit (127);
}