signals

Pausing a process?

懵懂的女人 提交于 2019-11-27 23:48:50
问题 Is there a way to pause a process (running from an executable) so that it stops the cpu load while it's paused, and waits till it's unpaused to go on with its work? Possibly in python, or in some way accessible by python. 回答1: By using psutil ( https://github.com/giampaolo/psutil ): >>> import psutil >>> somepid = 1023 >>> p = psutil.Process(somepid) >>> p.suspend() >>> p.resume() 回答2: you are thinking of SIGTSTP -- the same signal that happens when you push CTRL-Z . This suspends the process

waiting for a signal

荒凉一梦 提交于 2019-11-27 23:43:45
I am working on an application which uploads the content of the file to server. To upload the file to server I am using ‘QNetworkAccessManager’ class. Since it works as asynchronous way, I changed it to work as synchronous way by using QEventLoop. Class FileTransfer { Public : QNetworkAccessManager mNetworkManager; Void Upload(QNetworkRequest request, QIODevice *data) { responce = mNetworkManager.put(request, data); EventLoop.exec(); ReadResponce(responce); } Void Stop() { responce ->close(); } } In my sample application I have 2 windows. 1st to select the files and 2nd to show the progress.

longjmp() from signal handler

↘锁芯ラ 提交于 2019-11-27 23:17:52
I'm using the following code to try to read an input from user and timeout and exit if more than 5 seconds pass. This is accomplished through a combination of setjmp/longjmp and the SIGALRM signal. Here's the code: #include <stdio.h> #include <setjmp.h> #include <unistd.h> #include <string.h> #include <sys/signal.h> jmp_buf buffer; // this will cause t_gets() to return -2 void timeout() { longjmp(buffer, 1); } int t_gets(char* s, int t) { char* ret; signal(SIGALRM, timeout); if (setjmp(buffer) != 0) return -2; // <--- timeout() will jump here alarm(t); // if fgets() does not return in t

How do I get tcsetpgrp() to work in C?

安稳与你 提交于 2019-11-27 22:58:31
I'm trying to give a child process (via fork() ) foreground access to the terminal. After I fork() , I run the following code in the child process: setpgid(0, 0); And: setpgid(child, child); In the parent process. This gives the child its own process group. The call to setpgid() works correctly. Now I want to give the child access to the terminal. I added the following to the child after the setpgid() call: if (!tcsetpgrp(STDIN_FILENO, getpid())) { perror("tcsetpgrp failed"); } After that, there is an execv() command to spawn /usr/bin/nano . However, instead of having nano come up, nothing

Drawing sine wave with increasing Amplitude and frequency over time

半腔热情 提交于 2019-11-27 22:50:27
问题 I am trying to plot a sine wave where the amplitude increases over time and the frequecy increases over time as well. I draw a normal sine wave as shown below but I couldn't change the amplitude and frequency. Any Ideas? t = [ 0 : 1 : 40 ]; % Time Samples f = 500; % Input Signal Frequency fs = 8000; % Sampling Frequency x = sin(2*pi*f/fs*t); % Generate Sine Wave figure(1); stem(t,x,'r'); % View the samples figure(2); stem(t*1/fs*1000,x,'r'); % View the samples hold on; plot(t*1/fs*1000,x); %

Problem in Timers and signal

本秂侑毒 提交于 2019-11-27 22:34:38
I have implemented a POSIX timer using timer_create( ) API, and this will generate SIGUSR1 when the timer expires for which i have put a handler code. Now the problem is, if this program receives another SIGUSR1, then the same signal handler will be invoked and caught. Is there any way to prevent this, so that the handler can catch signals only generated by the timer? Will this work for you? (Modified the code from example in timer_create man page.) #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #include <time.h> #define CLOCKID CLOCK_REALTIME #define SIG

Proper usage of volatile sig_atomic_t

雨燕双飞 提交于 2019-11-27 22:13:44
According to this site, one can use variables of type volatile sig_atomic_t inside a signal handler. Now my question is, would for example something like the following code still be atomic and thus introduce no race conditions? Assume that we are using a multicore processor ( EDIT : running a multithreaded program). Does volatile sig_atomic_t even work for multicore systems in the first place or should we use the atomic<unsigned int> of C++11 for signal handlers on a multicore system ( EDIT : running a multithreaded program)? volatile sig_atomic_t a; static void signal_handler(int sig, siginfo

Can a C program continue execution after a signal is handled?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 21:44:37
问题 I'm new at signal handling in Unix through C and I have been looking at some tutorials on it (out of pure interest). My questions is, is it possible to continue execution of a program past the point where a signal is handled? I understand that the signal handling function does the cleanup but in the spirit of exception handling (such as in C++), is it possible for that signal to be handled in the same fashion and for the program to continue running normally? At the moment catch goes in an

How to handle the signal in python on windows machine

拥有回忆 提交于 2019-11-27 21:16:11
I am trying the code pasted below on Windows, but instead of handling signal, it is killing the process. However, the same code is working in Ubuntu. import os, sys import time import signal def func(signum, frame): print 'You raised a SigInt! Signal handler called with signal', signum signal.signal(signal.SIGINT, func) while True: print "Running...",os.getpid() time.sleep(2) os.kill(os.getpid(),signal.SIGINT) Python's os.kill wraps two unrelated APIs on Windows. It calls GenerateConsoleCtrlEvent when the sig parameter is CTRL_C_EVENT or CTRL_BREAK_EVENT . In this case the pid parameter is a

Alternative to sun.misc.Signal

蹲街弑〆低调 提交于 2019-11-27 21:05:16
I started research to find an alternative to the sun.misc.Signal class, because it could be unsupported in upcoming JDKs (we're currently working on 1.6). When I build the project I get: warning: sun.misc.SignalHandler is Sun proprietary API and may be removed in a future release I came across multiple solutions but they don't fit my project e.g. in this question . This is unacceptable in my situation because: Signals are used not only for killing application The application is huge - every conceptual change of communication between modules/JVMs could take years to implement Thus, the