#include <stdio.h>
#include <sys/types.h>
#include <string.h>
int main()
{
char *ip;
char *temp[10];
pid_t pid;
pid = fork();
if (pid == 0) {
int i = 0;
do {
gets(ip);
temp[0] = strtok(ip, " ");
while (temp[++i] != NULL) {
temp[i] = strtok(NULL," ");
}
pid_t pid2;
pid2 = fork();
if (pid2 == 0) {
execvp(temp[0], temp);
}
} while(strcmp(temp[0], "quit"));
if (!strcmp(temp[0],"quit")) {
return;
}
} else if (pid < 0) {
fprintf(stderr,"error in creating child");
} else if (pid > 0) {
wait(NULL);
}
}
此代码似乎不适用于 cd 命令。我该如何修复它?我对操作系统的概念相当陌生,任何帮助将不胜感激!:)