signals

Can preemptive multitasking of native code be implemented in user space on Linux?

孤人 提交于 2019-12-21 10:16:35
问题 I'm wondering if it's possible to implement preemptive multitasking of native code within a single process in user space on Linux. (That is, externally pause some running native code, save the context, swap in a different context, and resume execution, all orchestrated by user space but using calls that may enter the kernel.) I was thinking this could be done using a signal handler for SIGALRM , and the *context() family but it turns out that the entire *context() family is async-signal

Can preemptive multitasking of native code be implemented in user space on Linux?

℡╲_俬逩灬. 提交于 2019-12-21 10:16:05
问题 I'm wondering if it's possible to implement preemptive multitasking of native code within a single process in user space on Linux. (That is, externally pause some running native code, save the context, swap in a different context, and resume execution, all orchestrated by user space but using calls that may enter the kernel.) I was thinking this could be done using a signal handler for SIGALRM , and the *context() family but it turns out that the entire *context() family is async-signal

Pthread threads and signals

帅比萌擦擦* 提交于 2019-12-21 09:16:09
问题 I am using pthread library under Linux for creating threads and I have two questions about signal handling in such applications. I know that signal handlers are process-wide, which means that if I set handler in process every thread will have this signal handler, also I know that there is pthread_kill function for sending signals to particular threads. I have a question about sending signals using for example shell kill command, as far as I understand, if I type for example kill -INT PID I

Bash script: can not properly handle SIGTSTP

我与影子孤独终老i 提交于 2019-12-21 09:14:30
问题 I have a bash script that mounts and unmounts a device, which performing some read operations in between. Since the device is very slow, the script takes about 15 seconds to complete (the mount taking atleast 5-6 seconds). Since leaving this device mounted can cause other problems, I don't want this script to be interrupted. Having said that, I can correctly handle SIGINT (Ctrl+c), but when I try to handle SIGTSTP (Ctrl+z), the script freezes. Which means the signal is trapped but the handler

Which “fatal” signals should a user-level program catch?

a 夏天 提交于 2019-12-21 04:34:13
问题 First of all, I do know that there was a similar question here in the past. But that question wasn't answered properly. Instead, it diverted into suggestion what to do to catch signals. So just to clarify: I've done whatever needs to be done to handle signals. I have an application that forks a daemon that monitors the main process through pipe. If a main process crashes (e.g. segmentation fault), it has a signal handler that writes all the required info to pipe and aborts. The goal is to

What happens when a signal is received while already in a signal handler?

随声附和 提交于 2019-12-21 04:19:23
问题 I have a parent process spanning several child processes. I want to know when any child process exits by registering a SIGCHLD signal handler. The question is, what happens if another SIGCHLD (or any other signal) is received, while the parent process is already in a signal handler? I can think of the following outcomes: The signal is ignored The signal is queued, and will be processed as soon as the current handler returns The current handler is in turn interrupted, just like the main

Bash – How should I idle until I get a signal?

十年热恋 提交于 2019-12-21 03:59:16
问题 I have a script for launchd to run that starts a server, then tells it to exit gracefully when launchd kills it off (which should be at shutdown). My question: what is the appropriate, idiomatic way to tell the script to idle until it gets the signal? Should I just use a while-true-sleep-1 loop, or is there a better way to do this? #!/bin/bash cd "`dirname "$0"`" trap "./serverctl stop" TERM ./serverctl start # wait to receive TERM signal. 回答1: A plain wait would be significantly less

What is a signal in Unix?

徘徊边缘 提交于 2019-12-21 03:39:21
问题 This comment confuses me: "kill -l generally lists all signals". I thought that a signal means a quantized amount of energy. [Added] Please, clarify the (computational) signal in Unix and the physical signal. Are they totally different concepts? [Added] Are there major differences between paradigms? Is the meaning the same in languages such as C, Python and Haskell? The signal seems to be a general term. 回答1: I cannot believe that people are not comparing things such as hardware and software

Runtime error handling in Swift

跟風遠走 提交于 2019-12-21 03:38:20
问题 I am fully aware that Swift doesn't have a try/catch mechanism to catch exceptions (OK, Swift 2.0 now supports them). I also understand that many API methods return a NSError that will be filled with an error object if something goes wrong. So please don't point me to this question: Error-Handling in Swift-Language But this still doesn't explain how to react to runtime errors in your own code, like array-out-of-bounds accesses or force-unwrapping an optional value that is nil. For example:

SIGHUP for reloading configuration

巧了我就是萌 提交于 2019-12-21 03:14:13
问题 According to signal(7) , SIGHUP is used to detect hangup on controlling terminal or death of controlling process. However, I have come across a lot of OSS daemons(services) where SIGHUP is used to initiate a reload of configuration. Here are a few examples: hostapd , sshd , snort etc. Is this a standard(or a generally acceptable) way to implement a reload? If not, whats recommended? 回答1: SIGHUP as a notification about terminal closing event doesn't make sense for a daemon, because deamons are