다음에서는 자식 프로세스가 개체를 만듭니다. 그것은 시간의 특정 기간 후에 자신을 죽일 신호를 사용죽이면 오브젝트가 제대로 파괴됩니까?
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class Wut{
public:
Wut(){cout<<"obj being created" << endl;}
~Wut(){cout<<"obj being destroyeed" << endl;}
};
void alarmHandler(){
cout << "Alarm! Forcing child to kill itself" << endl;
kill(getpid(), SIGKILL);
}
int main(int argc, char* argv[]){
int status;
pid_t pid;
if((pid = fork()) == 0){
Wut hi;
signal(SIGALRM, (sighandler_t)alarmHandler);
alarm(1);
alarm(7);
sleep(10);
cout << "this will not get printed" << endl;
} else {
wait(&status);
cout << "Parent dies" << endl;
}
sleep(10);
return 0;
}
그러나이 생성 개체는 소멸자를 호출하지 제대로 때문에 파괴되면 어떻게 확실하지 않다.
아마도 "적절하게"파괴되지는 않았지만 그보다 덜 사라진 것은 아닙니다. 바주카포를 사용하고 있으며 대상이 제대로 파괴되었는지 묻습니다. –