signals

Handling SIGCHLD, how to record the return values of children as they die

为君一笑 提交于 2019-11-30 16:09:55
问题 void childSignalHandler(int signo) { int status; pid_t pid = wait(&status); struct PIDList* record = getRecordForPID(childlist, pid); if (record != NULL) record->returnValue = status; } Quick question: I want this handler to, when a child dies (this app spawns lots of children), get their return value and record it (last three lines). Will this do it, or am I getting all this API business wrong? Thank you for your time! (also, linux API terminology is creepy as hell, check for dying children

Printing stack trace from a signal handler

有些话、适合烂在心里 提交于 2019-11-30 15:24:01
问题 I need to print stack trace from a signal handler of 64-bit mutli-threaded C++ application running on Linux. Although I found several code examples, none of them compiles. My blocking point is getting the caller's (the point where the signal was generated) address from the ucontext_t structure. All of the information I could find, points to the EIP register as either ucontext.gregs[REG_EIP] or ucontext.eip. It looks like both of them are x86-specific. I need 64-bit compliant code for both

What is correct way to have single Signal Handler function for multiple Signals?

梦想与她 提交于 2019-11-30 15:02:30
问题 What is the best way in C on Linux for setting up a program that can handle multiple POSIX-signals with the same function? For example in my code I have a handler function that I want to generically call when ever a signal is caught to perform some actions: /* 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; } I have set up two signals

Basic signal handling in C++

╄→гoц情女王★ 提交于 2019-11-30 14:55:52
问题 This is a pretty basic scenario but I'm not finding too many helpful resources. I have a C++ program running in Linux that does file processing. Reads lines, does various transformations, writes data into a database. There's certain variables (stored in the database) that affect the processing which I'm currently reading at every iteration because I want processing to be as up to date as possible, but a slight lag is OK. But those variables change pretty rarely, and the reads are expensive

Printing stack trace from a signal handler

ぃ、小莉子 提交于 2019-11-30 14:10:56
I need to print stack trace from a signal handler of 64-bit mutli-threaded C++ application running on Linux. Although I found several code examples, none of them compiles. My blocking point is getting the caller's (the point where the signal was generated) address from the ucontext_t structure. All of the information I could find, points to the EIP register as either ucontext.gregs[REG_EIP] or ucontext.eip. It looks like both of them are x86-specific. I need 64-bit compliant code for both Intel and AMD CPUs. Can anybody help? there is a glibc function backtrace . The man page lists an example

Unix signal handling in (common) lisp

流过昼夜 提交于 2019-11-30 13:56:15
问题 I've done a bit of research on this subject and am turning up blanks. There seem to be implementation-dependent ways of doing Unix signal handling in Common Lisp, but is there a package that gives a cross-implementation way of doing signal handling? I would mainly like to listen for SIGINT and do a graceful shutdown in my app. I'm using Clozure CL 1.7 on linux...like mentioned, it would be great for a package for this, but if I have to resort to implementation-specific code, that's fine. I'm

Trying to make close sleep on Linux

青春壹個敷衍的年華 提交于 2019-11-30 12:47:19
I need to investigate/test the behavior of some code on Linux under conditions where close might be interrupted by signal handlers (either with or without SA_RESTART ). What is the most convenient setup to make the close syscall sleep for a measurable window of time during which I could try to hit the process with a signal? Some ideas: Intentionally slow/non-responsive NFS mount Custom FUSE driver But since these are a bit of a pain to setup, I'm wondering if there's anything more off-the-shelf I could use that could give the desired behavior. If nobody else has a better idea... You could

How to monitor an external process for events by its PID in C?

喜你入骨 提交于 2019-11-30 11:06:48
Is there any library which's got some function the allows one to monitor an external process for events by its pid_t ? I mean, monitoring whether an external process has exited, or whether it has created one or more child processes (with fork ), or whether it has become another executable image (via an exec or posix_spawn function family call) or whether a Unix signal was delivered to it. EDIT I need something that does not interfere with the execution of the program that is being monitored. So, I'm not supposed to use ptrace , since it stops the process which is being monitored when it emits

C#: How to force “calling” a method from the main thread by signaling in some way from another thread

人走茶凉 提交于 2019-11-30 09:33:53
问题 Sorry for long title, I don't know even the way on how to express the question I'm using a library which run a callback from a different context from the main thread (is a C Library), I created the callback in C# and when gets called I would like to just raise an event. However because I don't know what will be inside the event, I would like to find a way to invoke the method without the problem of locks and so on (otherwise the third party user will have to handle this inside the event, very

Signal handling on Windows

一曲冷凌霜 提交于 2019-11-30 09:11:50
I have a standalone PHP script, and I would handle a signal sent from Windows OS to do a graceful shutdown when a "kill signal" is issued. How can I do that on Windows? While the only other answer here is succinct and accurate, it lacks detail on why there isn't signal support on Windows. First off, signals are a rather limited and outdated way of communicating with a process. There are many more richer ways to inform a process that it needs to drop what it is doing and do something else. Even on POSIX platforms, signal handlers are intended to be VERY lightweight - code in signal handlers has