int main()
{
alarm(5);
int cnt = 1;
while(true)
{
std::cout << "second = " << cnt << std::endl;
cnt++;
sleep(1);
}
return 0;
}void handler(int sig)
{
std::cout << "get sig: " << sig << std::endl;
exit(1);
}
int main()
{
signal(14, handler);//捕捉一下14号信号
alarm(5);//设置一个5秒的闹钟
int cnt = 1;
while(true)
{
std::cout << "second = " << cnt << std::endl;
cnt++;
sleep(1);
}
return 0;
}
include
include <unistd.h>
include <signal.h>
include
include
void handler(int sig)
{
alarm(1);
std::cout << "get sig: " << sig << std::endl;
}
int main()
{
signal(14, handler);
alarm(1);
while (true)
{
std::cout << "hello world" << std::endl;
sleep(1);
}
return 0;
}int cnt = 1;
void handler(int sig)
{
std::cout << "get sig: " << sig << std::endl;
std::cout << "cnt: " << cnt << std::endl;
exit(1);
}
int main()
{
signal(14, handler);
alarm(1);
while (true)
{
std::cout << "cnt: " << cnt << std::endl;
cnt++;
}
return 0;
}void handler(int sig)
{
std::cout << "get sig: " << sig << std::endl;
}
int main()
{
signal(11,handler);
int* ptr = nullptr;
*ptr = 100;
return 0;
}