signals

Is fork (supposed to be) safe from signal handlers in a threaded program?

喜欢而已 提交于 2019-12-04 08:56:30
问题 I'm really uncertain about the requirements POSIX places on the safety of fork in the presence of threads and signals. fork is listed as one of the async-signal-safe functions, but if there is a possibility that library code has registered pthread_atfork handlers which are not async-signal-safe, does this negate the safety of fork ? Does the answer depend on whether the thread in which the signal handler is running could be in the middle of using a resource that the atfork handlers need? Or

kill signal example

谁说胖子不能爱 提交于 2019-12-04 08:36:39
I'm trying this example that I took from: http://www.cs.cf.ac.uk/Dave/C/node24.html : #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> void sighup(); /* routines child will call upon sigtrap */ void sigint(); void sigquit(); main() { int pid; /* get child process */ if ((pid = fork()) < 0) { perror("fork"); exit(1); } if (pid == 0) { /* child */ printf("\nI am the new child!\n\n"); signal(SIGHUP,sighup); /* set function calls */ signal(SIGINT,sigint); signal(SIGQUIT, sigquit); printf("\nChild going to loop...\n\n"); for(;;); /* loop for ever */ } else /* parent */

signals sent by qtcreator on “stop”

穿精又带淫゛_ 提交于 2019-12-04 08:09:14
I am working on linux and I realized that my application was leaving behind daemon processes when I close it with the "Stop" button on Qt creator IDE. I want to handle these cases so the application close the same way as when I close the main window. To write the handlers, I need to know which signals it corresponds to. Digging into QtCreator's code, I can see that QtCreator uses a QProcess internally to launch your app. The red "stop" button is connected to ApplicationLauncher::stop() , which terminates your process in one of two ways depending if it's a GUI app or a console app, but in both

libsigsegv and responding to a stack overflow

自作多情 提交于 2019-12-04 07:17:00
We are attempting to test student code, and in an effort to automate the process, we'd like to detect if a student's code overflows the stack. I've met with some success using the libsigsegv library and its corresponding stackoverflow_install_handler. It works brilliantly, until the student's code blows the stack twice. For example, here's some sample output: [# ~]$ ledit ./interpreter -> (use solution) -> (fun 1 2) *** Stack overflow detected *** -> (fun 1 2) Signal -10 [# ~] The initial " * Stack overflow detected * " is the desirable output. After blowing the stack for the second time, all

posix threads block signal and unblock

落花浮王杯 提交于 2019-12-04 06:52:37
Is there a way to block certain signals and unblock other signals in the same set? I just dont seem to get my head around it! An example sigset_t set; sigemptyset(&set); sigaddset(&set, SIGUSR1); // Block signal SIGUSR1 in this thread pthread_sigmask(SIG_BLOCK, &set, NULL); sigaddset(&set, SIGALRM); // Listen to signal SIGUSR2 pthread_sigmask(SIG_UNBLOCK, &set, NULL); pthread_t printer_thread1, printer_thread2; pthread_create(&printer_thread1, NULL, print, (void *)&f1); pthread_create(&printer_thread2, NULL, print, (void *)&f2); bool tl = true; while(1) { if(tl) { // thread1 does something

No overload matches this call. Type 'string' is not assignable to type 'Signals'

拟墨画扇 提交于 2019-12-04 05:52:56
I am using typescript to build a micro service and handling signals as well. The code was working fine till few days ago but recently it started throwing error. Couldn't find a fix for the issue. code for handling signals. It is just part of the file. src/main.ts enum signals { SIGHUP = 1, SIGINT = 2, SIGTERM = 15 } const shutdown = (signal, value) => { logger.warn("shutdown!") Db.closeAll() process.exit(value) } Object.values(signals).forEach(signal => { process.on(signal, () => { logger.warn(`process received a ${signal} signal`) shutdown(signal, signals[signal]) }) }) When I do ts-node src

order of SIGCONT and SIGHUP sent to orphaned linux process group

浪子不回头ぞ 提交于 2019-12-04 05:31:01
问题 APUE says Since the process group is orphaned when the parentterminates, POSIX.1 requires that every process in the newly orphaned process group that is stopped (as our child is) be sent the hang-up signal (SIGHUP) followed by the continue signal (SIGCONT) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <errno.h> #define errexit(msg) do{ perror(msg); exit(EXIT_FAILURE); } while(0) static void sig_hup(int signo) { printf("SIGHUP received, pid = %d\n",

How to gracefully terminate an asyncio script with Ctrl-C?

我的梦境 提交于 2019-12-04 05:24:34
I've read every post I could find about how to gracefully handle a script with an asyncio event loop getting terminated with Ctrl-C, and I haven't been able to get any of them to work without printing one or more tracebacks as I do so. The answers are pretty much all over the place, and I haven't been able implement any of them into this small script: import asyncio import datetime import functools import signal async def display_date(loop): end_time = loop.time() + 5.0 while True: print(datetime.datetime.now()) if (loop.time() + 1.0) >= end_time: break await asyncio.sleep(1) def stopper

Android _Unwind_Backtrace inside sigaction

两盒软妹~` 提交于 2019-12-04 05:02:04
I am trying to catch signals such as SIGSEGV in my Android NDK app for debugging purpose. For that, I have set up a sigaction that is called. I am now trying to get the stack of the call. The problem is that _Unwind_Backtrace only works on current stack and sigaction runs inside its own stack. So, is there a way to get the stack of the execution pointer that received the signal? (Basically tell _Unwind_Backtrace to unwind another stack than the current?) I should point out that : Using backtrace() and backtrace_symbols() is not an option since those functions are not delivered in the Android

PyQt_PyObject equivalent when using new-style signals/slots?

一世执手 提交于 2019-12-04 04:56:21
So I have a need to pass around a numpy array in my PyQt Application. I first tried using the new-style signals/slots, defining my signal with: newChunkToProcess = pyqtSignal(np.array()) , however this gives the error: TypeError: Required argument 'object' (pos 1) not found I have worked out how to do this with the old-style signals and slots using self.emit(SIGNAL("newChunkToProcess(PyQt_PyObject)"), np.array([5,1,2])) - (yes, that's just testing data :), but I was wondering, is it possible to do this using the new-style system? The type you're looking for is np.ndarray You can tell this from