QNX 클래스 노트에이 예가 있는데, 필자의 교수가 그 출력을 어떻게 내놓았는지 파악할 수 없습니다. 아무도 이것을 철저히 설명 할 수 있습니까? 이 프로그램은 부모 프로세스를 실행C 신호 처리기 교수의 예 설명
가1234 PID 및 자식 프로세스가 있음 5678
출력 5678 : 카운터 = 1,234 0 : 카운터 = 10
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
/*
* getpid() - returns the current processes pid.
* getppid() - returns the parent processes pid.
*/
int counter = 0;
void signal_handler(int signo)
{
counter++;
}
int main(int argc, char *argv[]) {
int i = 0;
int rv;
struct sigaction sa;
sa.sa_handler = signal_handler;
//queue signals.
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sigaction(SIGUSR1, &sa, NULL);
switch(fork())
{
case 0:
for(i = 0; i < 10; i++)
{
kill(getppid(), SIGUSR1);
}
break;
default:
wait(&rv);
break;
}
printf("%d: counter = %d\n", getpid(), counter);
return 0;
}
그럼 .. 직접 해 보셨습니까? –
@ EugeneSh.i 않았다 –
그것은 어떻게 할 것이라고 생각하니? 왜? – rici