int status = - 1;
int w = 0;
void timer_handler1( int signum) {// timer handler from SIGALRM
static int count = 0;
static int sigstopNext = 0;
struct timeval ts;
gettimeofday(&ts, NULL);
//Intervals set to change status
if (w != 0) {
if( count == 1) {
printf("%06d: SIGSTOP happened here at count %d\n",ts.tv_usec, count);
status = 0
}
else if (count % (w + 1) == 0 ) {
printf("%06d SIGCONT happened here at count %d\n",ts.tv_usec, count);
sigstopNext = 1;
status = 1;
} else if (sigstopNext == 1) {
sigstopNext = 0;
printf("%06d SIGSTOP happened here at count %d\n", ts.tv_usec, count);
status = 0;
}
}
count += 1;
}
//MAIN CODE
if (pid == 0) { //child process
execl(argv[1], argv[1], argv[2], NULL);
} else { //parent process
if(status == 1) {
printf("Sending SIGCONT\n");
if (kill(0,SIGCONT) == 0) {
printf("SIGCONT sent successfully!\n");
}
} else if (status == 0){
printf("Sending SIGSTOP\n");
if (kill(0,SIGSTOP) == 0) {
printf("SIGSTOP sent successfully!\n");
}
}
wait(NULL);
}
Привет, я пытаюсь создать программу для записи, которая будет периодически генерировать SIGSTOP и SIGCONT на основе таймера POSIX.
Так что на каждом интервале SIGALRM будет вызывать обработчик, который будет изменить переменную «status» с 1 на 0/0 на 1.
Таким образом, из основного кода, если status = 0, вызывается kill (0, SIGSTOP), если status = 1, kill (1, SIGCONT) ).
Я не уверен, что это правильный способ отправки сигналов от родителя к ребенку на основе таймера, потому что моя программа зависает