使用SIGINT [英] Using SIGINT

查看:83
本文介绍了使用SIGINT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此 http://www.cplusplus.com/reference/ clibrary / csignal / signal.html

SIGINT 通常由用户使用/引起。如何在C ++中导致 SIGINT ?我看到了一个使用 kill(pid,SIGINT); 的示例,但我宁愿以另一种方式引起它。

SIGINT is generally used/cause by the user. How do i cause a SIGINT in c++? i seen an example using kill(pid, SIGINT); but i rather cause it another way. Also i am using windows.

推荐答案

C89和C99在signal.h中定义了raise():

C89 and C99 define raise() in signal.h:

#include <signal.h>

int raise(int sig);

此函数向调用进程发送信号,等效于

This function sends a signal to the calling process, and is equivalent to

kill(getpid(), sig);

如果平台支持线程,则调用等效于

If the platform supports threads, then the call is equivalent to

pthread_kill(pthread_self(), sig);

成功时返回值为0,否则返回非零。

The return value is 0 on success, nonzero otherwise.

这篇关于使用SIGINT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆