私は、execveを使ってSegFaultを持つプログラムを実行し、シグナルを捕まえた後に終了するフォークを作成するプログラムを持っています。私のシグナルハンドラでは、 "Segmentation fault(Core dumped)"を取得する必要がありますが、何も書かれていません。だから私は尋ねている:どのように子供プロセスでsegfault信号を処理するのですか?子プロセスでのSIGSEGVシグナルハンドリング
int child_management(char **env, char **arguments)
{
char **paths;
char *current_path;
char *target_path;
int found;
int i;
i = -1;
found = 0;
paths = get_paths(env);
if (execve(arguments[0], arguments, env) == -1)
{
while (paths[++i] != NULL)
{
current_path = my_strcat(paths[i], "/");
target_path = my_strcat(current_path, arguments[0]);
found = (execve(target_path, arguments, env) == -1 && found == 0) ? 0 : 1;
free(current_path);
free(target_path);
}
if (!found && !is_existing_builtin(arguments[0]))
my_printf("%s: Command not found.\n", arguments[0]);
}
free(arguments);
free(paths);
if (signal(SIGSEGV, segf_handler) == SIG_ERR);
exit(0);
}
void segf_handler()
{
my_printf("Segmentation fault (Core dumped)\n");
}
int execute_program(char *str, char **av, char **env)
{
pid_t pid;
char **arguments;
pid = fork();
arguments = my_str_explode(str, ' ');
if (pid > 0)
{
parent_management(pid, arguments, env);
}
else if (pid == 0)
{
child_management(env, arguments);
}
}
は私がexerciceをやっていることに注意してくださいと私は
おそらく、あなたの 'my_printf'が壊れていますか?あるいは、セグメンテーションが起こっていないのでしょうか?ところで、 'execve'が成功すれば、' signal'関数にはまったく慣れることができません... –
通常のprintfでさえ、動作しません。私がbashで指定のプログラムを起動すると、segfaults! – Orionss
私がアップデートで言ったように、成功すれば 'execve'は返されません。 –