停止自己的进程
相关代码非常庞大,因此很抱歉我无法将其发布在这里。问题是:-我编写了一个小程序,如下所示:
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<signal.h>
int main()
{
printf("\n Process id",getpid());
fflush(stdout);
if(kill(getpid(),SIGSTOP)!=0)
printf("\nError");
}
运行后,我得到以下o/p:
Process id 2664
[1]+stopped ./test_SIGSTOP
[Directory Path]$
这正是预期的。但在我所说的实际程序中,我说的是非常大的......控制权就在kill调用之上(我知道它是因为我有打印语句并刷新它们)并挂起,而不会自动停止进程和命令提示符的出现。 将不胜感激指点。 感谢
The concerned code is very huge and hence i am sorry i cannot post it here. The issue is:- I wrote a small program as follows:
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<signal.h>
int main()
{
printf("\n Process id",getpid());
fflush(stdout);
if(kill(getpid(),SIGSTOP)!=0)
printf("\nError");
}
Upon running i get the following o/p:
Process id 2664
[1]+ stopped ./test_SIGSTOP
[Directory Path]$
Which is exactly what is expected. But in my actual program which i said is very huge...control comes to just above the kill call(I know it as I have print statements and fflushed them) and hangs without automatically stopping the process and appearence of the command prompt.
Would be gratefull for pointers.
Thank
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将调试器附加到正在运行的程序并找出它挂起的位置/原因。另外,
raise()
函数使用起来更方便。但首先,使用 ps 并检查进程的标志来确认其状态(运行/睡眠/停止)。You can attach a debugger to a running program and find out where/why it hangs. Also, the
raise()
function is more convenient to use. But first, use ps and inspect the process's flags to confirm its status (running / sleeping / stopped).