Directly on the code:
#include "apue.h" #include <sys/wait.h>int main (void) { char buf[maxline];/* form apue.h 4096 */ pid_t pid; int status; printf ("percent"); /* Print PROMT (printf requires percent to print%) * /while (Fgets (buf, MAXLINE, stdin)! = NULL) { if (Buf[strlen (BUF) -1] = = ' \ n ') { Buf[strlen (BUF)-1] = 0;/* Replace newline while null */ } if ((PID = fork ()) < 0) { C13/>err_sys ("fork Error"); } else if (PID = = 0) { execlp (buf, buf, (char *) 0); Err_ret ("couldn ' t execute:%s", buf); Exit (127); } /* Parent */ if (PID = Waitpid (PID, &status, 0)) < 0) { err_sys ("Waitpid error"); } printf ("percent"); } Exit (0);}
Many times do not like CSDN This code display, and then affixed to the vim
Test:
The function of this applet is that it cannot pass parameters to the command, for example, we cannot specify a directory name to list, we can only run it in the current working directory.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Shell-like Program (Basic implementation portion of Shell programs)