#实现shell普通功能的程序
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
int main()
{
char cmd[100];
int pid;
while(1){
printf("zhang$:");
scanf("%s",cmd);
if((pid=fork())<0){
perror("fork");
exit(-1);
}
else if(pid == 0){
execlp(cmd,cmd,NULL);
exit(-1);
}
wait(NULL);
}
return 0;
}
查看7道真题和解析