How can I know if a Qprocess has successfully finished its execution or has been killed forcefully using process.kill()? In both the case the exitstatus() is normalExit.
Is there any way?
I don't think there's any specific function call, if that's what you're looking for. You didn't mention what platform you're using, but in the case of Linux, calling kill() sends a message to the process for it to terminate, so as far as the Process is concerned, everything is ok when it finished.
What you may be able to do though is subclass QProcess and overload the kill function to set a boolean value which you can check when the QProcess emits finished().
QProcesss::exiStatus() will give you this information. If the QProcess exits normally it will return Normal Exit or if the process was killed it will return Crash Status.
You can also check the QProcess::exitCode() to see the exact exit code for that process.
The following is a Linux example if a process is killed with SIGKILL.
QProcess subproc;
// Run the process here
subproc.waitForExit();
qDebug() << "Status: " << subproc.exitStatus()
qDebug() << "Code: " << subproc.exitCode()
While the sub-process is running run the following Linux command:
kill -9 <subproc PID>
Then the following is printed:
Status: CrashExit
Code: 9
Without using the kill command on the sub-process the following is output is observed:
Status: NormalExit
Code: 0
Related
I am trying to setup a websocket server as described in this boost beast example.
Everything works fine except that the websocket stream read throw unexpeced system error with error code of "End of file" and "Operation cancelled"
beast::flat_buffer buffer;
try {
ws->read(buffer); // ws is in the free store
}
catch(beast::system_error const& se) {
if(se.code() == websocket::error::closed) {
LOG_INFO << "ws closed, exiting handing thread..";
break;
}
LOG_WARNING << "exception: " << se.code() << ", " << se.code().message();
}
After client connected to this server, and the server start to read incoming msg from the client with
ws->read(buffer);
From time to time, one End of file system_error and many operation cancelled system error are caught and printed as below:
WARNING exception: asio.misc:2, End of file
WARNING exception: system:125, Operation canceled
WARNING exception: system:125, Operation canceled
WARNING exception: system:125, Operation canceled
I googled around, End of file is probably caused by underlying tcp socket is closed, but the issue is that the disconnct happens very often and that does not make sense. And what exactly will cause Operation cancelled system error?
It turns out to be caused by bad netowrk. When I disable some VPN, the issue is gone.
I'm writing a small program in Haskell which manipulates the commands arecordmidi and aplaymidi to record short improvisations on my digital piano through MIDI. I will press the R key, my program will create a new subprocess with the command arecordmidi. When I press R again, I want my recording to stop, by terminating the command arecordmidi.
How do I terminate the arecordmidi subprocess? If in a shell, CTRL+C would stop recording. This is what I want.
I'm using the following code to create the subprocess:
import System.Process
main = do
let rec_command = "arecordmidi -p \"CASIO USB-MIDI\" myRecording.midi"
process <- createProcess (shell rec_command)
-- I could try the following code, but the documentation of System.Process
-- says it's bad to use terminateProcess:
let (_, _, _, processHandle) = process
terminateProcess processHandle
terminateProcess sends a SIGTERM (terminate) signal to the process, which corresponds to the default behavior of the unix command kill, which generally is not what you want when trying to end a process nicely.
Ctrl+C sends the signal SIGINT (interrupt), which many applications handle by an orderly shutdown, and in your case probably results in the arecordmidi process saving outstanding data, and closing any pipes and files.
Looks like the way to send SIGINT with System.Process is with interruptProcessGroupOf.
To monitor a log file I have to connect to an ssh connection and redirect the output of the log file(let's call it RemoteLog.txt) out to a local machine so it can be read by a java program and put on a GUI.
Right now I have the output redirected out of the ssh connection and onto the local machine with the command:
ssh remote#ip.address tail logs/RemoteLog.txt -f > ~/Log/LocalLog.txt
and everything works fine technically with one exception: for some reason LocalLog.txt only gets updated with the changes to RemoteLog.txt every 35 seconds to the millisecond.
It doesn't matter the number of changes to RemoteLog, the number of lines specified with the tail command, or using the >> operator vs the > operator; there is always a 35 second delay between updates of LocalLog.txt while RemoteLog is constantly updating.
Does anyone have any clue why this might be?
I would like to assign some code that will be run when R is killed, for instance, save(list=ls(),file="dump.RData"). I thought this would be by trapping signals, e.g. SIGTERM, as referred to in this post, but there's nothing about signals from the shell in ?conditions.
?conditions does mention user interrupts; you can e.g. catch a Ctrl-C with withCallingHandlers( Sys.sleep(10), interrupt=function (e){cat("I saw that.\n")} ), but this doesn't catch SIGTERM.
How can I do this?
Indeed if you send SIGUSR1 to an R process, it will dump the workspace and stop. On Linux you can do that with
kill -USR1 Rpid
where Rpid is the process id of the R instance you want to stop. You can find it with pgrep for instance.
If R is running in a terminal, you can interrupt it with CTRL-Z and then type
kill -USR1 %
I'm using monit 5.4 on Mac 10.7.4 machine. When i tried to execute a example configuration
check process syslogd with pidfile /var/run/syslogd.pid
start program = "/etc/init.d/sysklogd start"
stop program = "/etc/init.d/sysklogd stop"
if 5 restarts within 5 cycles then timeout
from monit wiki page, I get the following error.
'syslogd' process is not running
'syslogd' trying to restart
'syslogd' start: /etc/init.d/sysklogd
'syslogd' failed to start
Monit does not take the complete command given in the "start program" of the monitrc file. It just takes the first word in the command and tries to execute it and fails. Is this a known issue? If yes, does it have a workaround? If not, what am i missing here and how to get it working?
Thanks in advance.
Try this (from http://mmonit.com/wiki/Monit/FAQ#execution)
start program = "/bin/bash -c '/etc/init.d/blah start'"
Does /etc/init.d/sysklogd actually exist?
On 10.8 I have /etc/init.d/syslog and manually running /etc/init.d/syslog restart works fine.