#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
int main()
{
while(1)
{
#define MAX 1024
char buf[MAX];
fgets(buf,MAX,stdin);
int len =strlen(buf);
buf[len - 1] = 0;
if(strcmp("quit",buf) ==0)
{
exit(0);
}
pid_t pid = fork();
if(pid == 0)
{
if(execlp(buf,buf,NULL) <0)
{
perror("exec");
//exit(0);
}
/*setsid();
chdir("/");
umask(0);
int fdtablesize = getdtablesize();
int fd;
for(fd = 0;fd < fdtablesize;fd++)
close(fd);
fprintf(stdout,"rong?->$:");
*/
}
else if(pid > 0)
printf("rightrunning!\n");
else
perror("create child process wrong!");
}
exit(0);
}
UNIX高级编程之简易版shell
最新推荐文章于 2024-07-25 20:45:01 发布