Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

c - -SIGCONT does not continue paused process?

The following process does not continue after running kill -SIGCONT pid from another terminal.

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("paused
");
    pause();
    printf("continue
");

    return 0;
}

I expect the program to continue after sending the signal and printing "continue". How come this doesn't work as expected?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

pause() is documented to

cause the calling process (or thread) to sleep until a signal is delivered that either terminates the process or causes the invocation of a signal-catching function.

But SIGCONT only continues a process previously stopped by SIGSTOP or SIGTSTP.

So, you might want to try:

 kill(getpid(), SIGSTOP);

Instead of your pause()

Also, you might want to look at sigsuspend().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...