sigaction

macOS `sigaction()` handler with `SA_SIGINFO` does not include `si_pid`

穿精又带淫゛_ 提交于 2019-12-10 14:05:12
问题 I'm trying to write a signal handler which needs to know the pid of the process that sends the signal. I'm having no luck with getting anything useful from the siginfo_t passed into my handler on macOS 10.14 with Xcode 10. I've reduced my code to the below minimal sample to demonstrate the issue. In this sample I spawn a child process to send the signal I want to test which is defaulted to SIGTERM , but no other signal I've tried works any better. Assuming you want to build and test this on a

Sigaction and porting Linux code to Windows

。_饼干妹妹 提交于 2019-12-09 16:18:05
问题 I am trying to port caffe (developed for Linux) source code to Windows environment. The problem is at sigaction structure at signal_handler.cpp and signal_handler.h . The source codes are shown below. My query is which library or code replacement can be done to make this sigaction works in Windows. ///Header file #ifndef INCLUDE_CAFFE_UTIL_SIGNAL_HANDLER_H_ #define INCLUDE_CAFFE_UTIL_SIGNAL_HANDLER_H_ #include "caffe/proto/caffe.pb.h" #include "caffe/solver.hpp" namespace caffe { class

IPC研究(1) -- signals

断了今生、忘了曾经 提交于 2019-12-06 19:53:34
==================================================================== IPC ---- Signals Question: Why is it unsafe to call printf() in a signal handler? A: A signal handling fucntion could be interrupted in the middle and called again by something eles. So a signal handling function is not just recurisve, but also re-entrant. This means, any system calls that are not re-entrant but are called inside a signal handler are considered unsafe. For system calls that are safe to call inside a signal handler, refer to page 524 in Book "Linux Programming". Related system calls: signal (deprecated) kill

Sigaction and porting Linux code to Windows

跟風遠走 提交于 2019-12-04 04:35:39
I am trying to port caffe (developed for Linux) source code to Windows environment. The problem is at sigaction structure at signal_handler.cpp and signal_handler.h . The source codes are shown below. My query is which library or code replacement can be done to make this sigaction works in Windows. ///Header file #ifndef INCLUDE_CAFFE_UTIL_SIGNAL_HANDLER_H_ #define INCLUDE_CAFFE_UTIL_SIGNAL_HANDLER_H_ #include "caffe/proto/caffe.pb.h" #include "caffe/solver.hpp" namespace caffe { class SignalHandler { public: // Contructor. Specify what action to take when a signal is received. SignalHandler

struct sigaction incomplete error

匿名 (未验证) 提交于 2019-12-03 01:32:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Although including I get an error saying that struct sigaction is an incomplete type. I have no Idea what to do with it. Please help #include struct sigaction act; int main(int argc, char** argv) { int depth; /* validate arguments number*/ if(argc \n"); exit(1); } /* register the realtime signal handler for sigchld*/ /*173*/ memset(&act,0,sizeof(act)); act.sa_handler = sigproc; sigaction(SIGCHLD, /* signal number whose action will be changed */ &act, /* new action to do when SIGCHLD arrives*/ NULL); /* old action - not stored */ srand(time

How to generate a core dump in Linux when a process gets a segmentation fault?

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a process in Linux that's getting a segmentation fault. How can I tell it to generate a core dump when it fails? 回答1: This depends on what shell you are using. If you are using bash, then the ulimit command controls several settings relating to program execution, such as whether you should dump core. If you type ulimit -c unlimited then that will tell bash that its programs can dump cores of any size. You can specify a size such as 52M instead of unlimited if you want, but in practice this shouldn't be necessary since the size of core

进程间通信:信号

匿名 (未验证) 提交于 2019-12-03 00:22:01
一、信号产生、处理、分类 二、signal信号处理机制 五、信号相关函数 六、计时器 信号就像古代战场上打仗,摇什么旗子摆什么阵。双方已经约定好。能不使用信号就不要使用信号,因为是异步。 信号是硬件中断的软件模拟(软中断)。 需要掌握:1到31号信号。 ------------------------------------------------------------------------------------------------------------------------------------------------------------- 信号的产生: 信号的生成来自内核 ,让内核生成信号的请求来自3个地方: 1.用户:用户能够通过输入CTRL+c、Ctrl+\,或者是终端驱动程序分配给信号控制字符的其他任何键来请求内核产生信号; 3.进程:一个进程可以通过系统调用kill给另一个进程发送信号,一个进程可以通过信号和另外一个进程进行通信。 信号的处理: 进程接收到这两个信号后,只能接受系统的默认处理,即终止进程. 钩子:回调函数 默认处理的话,一般会把程序搞崩溃。 进程事先注册信号处理函数。当信号来了的时候 信号的分类: 同步信号:由进程的某个操作产生的信号,例如除0、内存访问违规; 异步信号:由像用户击键这样的进程外部事件产生的信号,再如,ctrl+z.

Linuxc 信号的使用2 sigqueue函数和sigaction函数

匿名 (未验证) 提交于 2019-12-02 21:59:42
1.进程A向进程B发送SIGUSR1信号; 2.进程B收到信号后,打印字符串“receive SIGUSR1”; 3.要求用sigqueue函数和sigaction函数实现以上功能; 源代码: sigqueue.c #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <signal.h> #include <unistd.h> int main() } sigaction.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> void tt(int sig); int main() { } void tt(int sig) { } 1.信号发送函数―sigqueue() 调用成功返回 0;否则,返回 -1。 功能 主要针对实时信号,支持带有参数信号,与函数sigaction()配合使用 参数说明 pid:接收信号的进程ID signo:待发送信号 sigval_t:信号传递的参数(4字节) 说明 调用sigqueue()时,sigval_t被拷贝到信号处理函数 sigqueue()发送非实时信号时 sigval_t包含的信息仍然能够传递给信号处理函数 仍然不支持排队

Why only async-safe functions should be called from a signal handler?

六月ゝ 毕业季﹏ 提交于 2019-11-29 17:08:32
I understand that, from a signal handler function sigaction() I should only call those functions that are "async-safe". But why is so? Calling an unsafe function may lead to undefined behavior. The Open Group Base Specifications Issue 7 (POSIX.1-2008), in its treatment of "Signal Concepts" , says: [W]hen a signal interrupts an unsafe function ... and the signal-catching function calls an unsafe function, the behavior is undefined. As to why unsafe functions are unsafe, there may be many reasons in a given implementation. However, a previous version of the standard, Issue 6 (POSIX.1-2004),

c++比例-libcurl多线程并发时的core【转载】

岁酱吖の 提交于 2019-11-28 19:50:20
转自: https://www.cnblogs.com/edgeyang/articles/3722035.html 浅析libcurl多线程安全问题 背景:使用多线程libcurl发送请求,在未设置超时或长超时的情况下程序运行良好。但只要设置了较短超时(小于180s),程序就会出现随机的coredump。并且栈里面找不到任何有用的信息。 问题:1.为什么未设置超时,或者长超时时间(比如601s)的情况下多线程libcurl不会core? 问题:2.进程coredump并不是必现,是否在libcurl内多线程同时修改了全局变量导致? 先来看下官方libcurl的说明: libcurl is free , thread-safe , IPv6 compatible , feature rich , well supported , fast , thoroughly documented and is already used by many known, big and successful companies and numerous applications . 可以看到官方自称licurl是线程安全的,是否真的如此?再来看看代码中用到的超时选项的说明: CURLOPT_TIMEOUT Pass a long as parameter containing the