- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在这里进行小型单元测试。但是程序并没有像我预期的那样工作。
char *args[2];
args[0] = (char*)"/usr/bin/firefox";
args[1] = NULL;
pid = fork();
printf("forked and my pid is %d\n",pid);
//check for errors
if (pid<0){
printf("Error: invoking fork to start ss has failed, Exiting\n ");
exit(1);
}
//the child process runs firefox
if (pid==0){
if (execv(args[0],args)<0){
perror("Error: running s with execvp has failed, Exiting\n");
}
printf("IVE BEEN KILLED\n");
}
//dad is here
printf("DAD IS GOING TO KILL U\n");
if (pid>0){
sleep(3);
kill(get_pidof(string("firefox")),SIGUSR1);
}
现在,我希望程序运行如下:1. child 运行 firefox(它确实如此)2.爸爸打印爸爸要杀了你(到目前为止还不错)3.firefox 会打开 3 秒然后关闭(也是这样)4. 子进程将完成运行 execv 并打印“IVE BEEN KILLED”。这不会发生。
我的目标是通过在 execv 继续运行后立即发出一些标志来知道 execv 运行的程序已经完成(我被杀死的 printf 所在的位置)。我有几千行的代码,除非必要,否则不想使用其他方法。
谢谢
最佳答案
execv()
用新进程替换当前进程。当 firefox 通过 execv()
启动时,printf("IVE BEEN KILLED\n")
基本上不再存在于进程中并且永远不会被执行(参见 man execv )。父进程有可能等待子进程 firefox 使用 wait() 退出。或者通过信号(例如 signal(SIGCHLD, child_exit_handler)
)提醒子进程的死亡。
关于c - fork() kill() 和 execv(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13290594/
该程序在嵌入式 Linux 上执行(内核版本:3.4.0)。在调用execve()之前,还调用了setgid()和setuid()切换到另一个用户(tstuser).用户存在,必要的条目在 /etc/
我使用 execv 和参数:$PATH 调用 echo,输出是 $PATH,而不是 $PATH 环境变量的实际值,这是我在 bash 中执行相同操作时得到的值。 为什么会发生这种情况?我传递了所有正确
我在使用此 execve 命令时遇到问题。我可以在我的程序中使用它来运行大多数其他命令,但如果我尝试执行 man ls 之类的操作,我会收到此错误。 man: can't execute pager:
在 C 程序中,main 函数通过查看 argc 知道在 argv 中传递了多少参数。我似乎不清楚 syscall execve 如何知道传递给它的参数数量。有人可以帮助解释 execve 如何处理参
我是新手,所以我可能对表达不准确。我需要用汇编程序在 C 中进行系统调用“execve”。我不使用任何库。不起作用的部分是 char *nul=(char *)0; char *argv[] = {
我的教授编写了一个程序,它使用 execve() 打印工作目录 (pwd),但我不明白其中的参数。 pid_t pid = fork(); if(pid int main(int argc, cha
我有一个名为“test”的程序,它执行另一个名为“hello”的程序。收到所需程序的名称后,我的程序似乎等待更多输入才能显示“hello”程序代码。示例代码片段 #include #include
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
我在使用 C 程序时遇到了一些神秘的情况,该程序在我的电脑上运行良好,但当我在我正在使用的服务器上编译它时却失败了。基本上execve执行失败。原来的程序不太大,所以我开始削减一些部分,以尝试了解问题
我正在尝试在 Linux 计算机上测试绝对路径以查找程序所在的位置,以便我可以使用特定参数运行它。问题是,当我找到它时,我不断向正确的路径添加更多字符串,并通过释放动态分配的内存来导致内存泄漏。堆栈转
我必须执行一个路径未知的命令。我可以到达环境路径,但如何使用它们?例如,如果有 5 个不同的路径,我应该在 execv 中尝试哪一个? /usr/lib/lightdm/lightdm:/usr/lo
我对此困惑了一段时间,现在我需要一些帮助。我正在尝试创建一个循环,该循环将 fork 子进程并通过 execve() 调用“echo hello”。 #include #include #inc
我的程序中有这个: execv (programname, (char **)argv); 我不确定命令是否真的被正确执行了。我怎样才能知道?这是在后台运行吗? 最佳答案 我强烈建议你买一本与你正在
我必须制作一个自定义 shell 作为学校项目,但我遇到了困难: int exec_shell(char **argv) // { if (execve(argv[0], (char **)a
我试图找到我当前的 PATH 以在我的 execv() 命令中使用它,但我仍然无法弄清楚如何找到任何提示的路径? 最佳答案 获取当前PATH variable从您的环境中(参见 environ(7)
了解 Linux 内核说 execve() 调用每个 linux_binfmt 对象的 load_binary(),并且 load_binary() Invokes the start_thread(
我们有一个从 inittab 启动的 stub ,execv 是我们的进程。 (ARM Linux 内核 2.6.25) 测试进程时,只有从 inittab 启动并执行时才会失败。如果在命令行上启动,
程序应该做什么的例子: ./executable ls -l 应该做同样的事 ls -l 所以基本上它是一个无用的 shell 命令解释器。 我创建了一个包含/bin/commandname 的字符串
我想编写一个程序来执行 Linux ls 命令。我真的只想输入 ls 而不是 /bin/ls,所以我想使用 execve (execvp 不是一个选项)。 我试过: char *env[] = { "
我有一项大学作业,我需要从管道中读取 bash 命令并执行该命令。我正在考虑使用 execv*,因为我可以通过以空格作为分隔符来创建缓冲区。问题是我不能使用 STL 库,而且我不知道应该如何创建这个缓
我是一名优秀的程序员,十分优秀!