我和我的朋友正在尝试编写一个 shell。我的问题是运行'cat'命令然后用^C退出STDIN会使我的程序在waitpid上出现段错误,所以退出我的程序......(我当然不想要什么!)
每个命令都运行良好,我没有任何其他问题......我只是在询问它以及如何解决这些(大)问题。
谢谢你们的帮助!请参阅我在下面执行命令的代码:
static int cmd_executeit(char **env, t_shell *shell, char *path)
{
pid_t forked;
int ret;
ret = 0;
if ((forked = fork()) == FAILURE)
return (bi_error(shell, "I can't fork with you :("));
if (forked == SUCCESS)
{
if (execve(path, shell->cmd, env) == FAILURE)
return (bi_error(shell, "Execution of the command failed"));
}
else
{
if (waitpid(forked, &ret, 0) < 0)
return (bi_error(shell, "I can't wait for this command. Sorry."));
}
if (WIFEXITED(ret) && (WEXITSTATUS(ret) == SUCCESS))
return (SUCCESS);
return (FAILURE);
}
我得到了答案,谢谢:)。