execv 会在前台还是后台运行它?
我的程序中有这样的内容:
execv (programname, (char **)argv);
我不确定该命令是否确实正确执行。我怎样才能找到答案?这是在后台运行吗?
I have this in my program:
execv (programname, (char **)argv);
I'm not sure if the command is actually being executed correctly. How can I find out? Is this being run in the background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我强烈建议您买一本与您想要完成的任务相关的书。如果你在每一步都提出一个关于SO的新问题,那将是一条非常漫长的路。我们乐于提供帮助,但有时书籍更好。
高级 UNIX 编程 是一本优秀的书籍,其中包含 shell 的完整示例,包括管道。事实上,示例程序可以免费下载(但我还是建议您拿起这本书的副本)。
I highly recommend getting a book that relates to the task you're trying to do. It's going to be a really long road if you ask a new question on SO on every step of the way. We love to help, but sometimes books are better.
Advanced UNIX Programming is an excellent one that contains a full sample of a shell, including pipelines. In fact, the example programs are available for download for free (but I recommend picking up a copy of the book anyway).
由于 execv 替换了当前进程,因此该命令将在与父进程相同的状态下运行。
了解命令是否执行的一种方法是让命令在控制台上打印一些内容(如果可能)。
Since execv replace the current process, the command will be run on the same state as the parent process.
One way to know if your command is executed is to make the command print something on the console, if it is possible.
我相信 execv() 应该用“programname”覆盖当前进程。如果你想在单独的进程中运行一个程序,你需要 fork() 或 system() ——我不相信后者是“标准”,但它似乎相当普遍。
I believe execv() is supposed to overlay the current process with "programname". If you want to run a program in a separate process, you want fork() or system() -- I don't believe the latter is "standard" but it seems to be fairly ubiquitous.
来自 execv 的手册页。
因此,如果您获得返回值,则表明出现了问题。
From man page of execv.
So, if you get a return value, something went wrong.