Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-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\n");
    pause();
    printf("continue\n");

    return 0;
}

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

like image 874
Lucas Avatar asked Jan 12 '12 05:01

Lucas


1 Answers

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().

like image 83
Timothy Jones Avatar answered Sep 21 '22 06:09

Timothy Jones