signals

How can I notify the main thread of some message on another thread without blocking and waiting?

非 Y 不嫁゛ 提交于 2019-12-07 15:23:29
I'm writing a c# component that will only be used internally at my company. The component encapsulates communication with a number of servers that particular desktop applications need to communicate with. The servers can send unsolicited messages to the component, which are 'caught' in a separate thread. I want the majority of this component to execute under the context of its creating thread. I do not wish the separate message thread to do any message processing. Instead, I would like to notify the main thread that there is a message awaiting processing. The reason for wanting to execute

how to get stdout of subprocess in python when receving SIGUSR2 /SIGINT

允我心安 提交于 2019-12-07 14:26:16
问题 I have the following simple python script: import os, subprocess,signal,sys import time out = None sub = None def handler(signum,frame): print("script.py: cached sig: %i " % signum) sys.stdout.flush() if sub is not None and not sub.poll(): print("render.py: sent signal to prman pid: ", sub.pid) sys.stdout.flush() sub.send_signal(signal.SIGTERM) sub.wait() # deadlocks....???? #os.kill(sub.pid, signal.SIGTERM) # this works #os.waitpid(sub.pid,0) # this works for i in range(0,5): time.sleep(0.1)

wait for children and grand-children

不羁的心 提交于 2019-12-07 13:51:46
问题 How can you wait until all children and grand-children have exited, without blocking in a signal handler? This is my attempt so far. #include <signal.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> int run = 1; void handler(int sig, siginfo_t *info, void *uap) { int exit_code; printf("sigchld pid %d\n", info->si_pid); pid_t pid = waitpid(-1, &exit_code, 0); if (pid == -1) { perror("waitpid()\n"); } else { printf("waitpid returned %d\n

GTK+ (2.0) - signal “clicked” on GtkEntry?

安稳与你 提交于 2019-12-07 11:30:10
问题 I'm testing some signals with GTK+ 2.0. I'm looking for a way to get a signal emitted when I click on a GtkEntry. if (widgets_info[i].action & IG_INPUT) { widget->frame[i] = gtk_entry_new_with_max_length(MAX_INPUT_LENGTH); gtk_entry_set_text(widget->frame[i], widgets_info[i].text); catch_signal(widget->frame[i], MY_SIGNAL, &change_entry, widget); } I have a pre-selected text in my entry ( widgets_info[i].text ) and i want this text to disappear if the user click on my GtkEntry. Does someone

Trapping CHLD signal - ZSH works but ksh/bash/sh don't?

泄露秘密 提交于 2019-12-07 11:13:00
问题 Here's a sample code where a shell script launches a few jobs in the background and upon receiving the CHLD signal (i.e. the child process termination) it will take some actions... The problem is that if the parent shell script is a ZSH one, it works just fine and traps the CHLD signals, but other shells do not ! why is that? #! /bin/zsh - function foo() { echo "Trapped CHLD signal!" } trap 'foo' CHLD ./child-work1.sh & ./child-work2.sh & ./child-work3.sh & echo 'waiting for the children'

Ignoring signals in parent process

大憨熊 提交于 2019-12-07 10:29:08
问题 I am trying to implement a shell program and I want the shell program to ignore SIG_INT(ctrl + c). But in my program the child also ignores the SIG_INT signal, which it should not because exec should take the child process to another program and that program should handle the SIG_INT signal by default. What should I do so that the child process terminates when ctrl + c is pressed. Newly edited: after I put signal(certain_signal, SIG_DFL) in the block my child process, my code works fine. But

What is the difference between POSIX reliable signals and POSIX real-time signals in Linux?

倖福魔咒の 提交于 2019-12-07 10:22:00
问题 I read the man page of a signal using man 7 signal where I see two types of signal. So, I have question, What is the difference between POSIX reliable signals and POSIX real-time signals in Linux? 回答1: These days, it might be better to phrase these as ordinary signal semantics versus realtime signal semantics. In some early UNIX systems, signals were unreliable in that they could be "lost", because there was no facility to block signals (to keep them pending). For example, code about to call

How to block signals in C?

混江龙づ霸主 提交于 2019-12-07 09:50:30
I'm trying to create a program that blocks the signal SIGUSR1 and the it unblocks the signal. In the middle I want to see that the signal is blocked using sigpending . But it always says that the signal isn't blocked, and I can use the signal when it's supposed to be blocked. This is the code that I have. #include <stdlib.h> #include <stdio.h> #include <signal.h> static void signals(int signaln) { switch (signaln) { case SIGUSR1: printf("Signal SIGUSR1\n"); break; } return; } main() { sigset_t set,set2; struct sigaction sigs; sigs.sa_handler = signals; sigemptyset(&sigs.sa_mask); sigs.sa_flags

How to get user data for aio signal handler in Mac OS X

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 08:49:24
问题 I am attempting to use the aio_* functions for asynchronous file IO under Mac OS X, but I am having problems with getting some form of user data into the signal handler. This is the code that sets up an operation: class aio_context { public: aio_context(int fildes, boost::uint64_t offset, const MyBufferClassPtr &buffer) { // The aiocb struct must be zeroed memset(&m_aiocb, 0, sizeof(struct aiocb)); // Set what to do m_aiocb.aio_fildes = fildes; m_aiocb.aio_buf = buffer->data(); m_aiocb.aio

Segmentation Fault Catch

不问归期 提交于 2019-12-07 08:34:05
问题 I have a python script and it will loop through bunch of maya files and do some stuff. But some time maya get seg fault and my script will stop there. I tried with signal and multiprocess. But both failed import os, optparse, glob, json, signal import maya.standalone import maya.cmds as cmds from multiprocessing import Process, Queue def loadMayaBd(): maya.standalone.initialize(name='python') def sig_handler(signum, frame): print "segfault" def doSome(args, options): signal.signal(signal