Linux上用于设置可以处理具有相同功能的多个POSIX信号的程序的最佳方法是什么?
例如,在我的代码中,我有一个处理程序函数,我希望在捕获信号时执行某些操作时通常会调用它:
/* Exit handler function called by sigaction */
void exitHandler( int sig, siginfo_t *siginfo, void *ignore )
{
printf("*** Got %d signal from %d\n", siginfo->si_signo, siginfo->si_pid);
loopCounter=0;
return;
}
Run Code Online (Sandbox Code Playgroud)
我通过对每个信号进行单独的sigaction调用来设置两个信号:
/* Set exit handler function for SIGUSR1 , SIGINT (ctrl+c) */
struct sigaction act;
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = exitHandler;
sigaction( SIGUSR1, &act, 0 );
sigaction( SIGINT, &act, 0 );
Run Code Online (Sandbox Code Playgroud)
这是设置此类处理的正确方法吗?有没有其他方法我不必枚举所有可能的信号数字?
我搜索了stackoverflow并看到了我的问题中的每个单词组合,但不是我的问题.
我有一个int数组,它恰好是一个2d数组.
const int themap[something][something] = { {0, ...
Run Code Online (Sandbox Code Playgroud)
我有一个结构,我希望在我的程序中有一个指向这个数组的指针
typedef struct {
int** mymap;
} THE_STRUCT
Run Code Online (Sandbox Code Playgroud)
在我的程序中,我想通过struct的指针迭代数组的值,但是如果我尝试通过它访问它,我的数据似乎已损坏.句法
int value;
THE_STRUCT mystruct;
mystruct = (int**) themap;
...
//access the map data from mystruct's pointer?
value = mystruct.mymap[x][y];
//doesn't seem to return correct values
Run Code Online (Sandbox Code Playgroud)
如果我直接使用数组(作为全局变量),那么从图片中取出结构可以使用相同的函数
int value;
...
//access the map directly
value = themap[x][y]
//everyone is happy!
Run Code Online (Sandbox Code Playgroud)
我想使用结构实际上它将携带其他信息以及我需要能够将指针分配给具有不同数据的其他数组的事实.