rclone.exe does not seem to respect a soft-kill request such as taskkill /im rclone.exe
a soft-kill sends a signal to the rclone.exe to close gracefully
and
unmount all mounted drives.
when i try to soft-kill this happens:
C:\data\rclone\scripts>taskkill /IM rclone.exe
ERROR: The process "rclone.exe" with PID 3000 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
SUCCESS: Sent termination signal to the process "rclone.exe" with PID 15936.
It looks like that rclone would have to respond to the WM_CLOSE message in order to terminate gracefully like this. Given that rclone isn't a GUI program and doesn't have any windows open this would be reasonably complicated and involve making a hidden windows to receive the event.
Another alternative to the kill would be to simulate sending CTRL-C to rclone. There are some ideas here:
after a lot of testing, it seems that sometimes a softkill will work and sometimes a softkill will not work.
it depends on how rclone is lauched.
i mount 3 different mounts and use taskkill to kill them.
in the first test, only 1 out of 3 were terminated.
in the second test, only 2 out of 3 were terminated.
in all my testing, i was not able to get all 3 rclone.exe to respect the softkill request.
test 1
start rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ x:
start /b rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ y:
rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ z:
and here is the output of
C:\data\rclone\scripts\rr\mount>tasklist /fi "imagename eq rclone.exe"
C:\data\rclone\scripts\rr\mount>taskkill /im rclone.exe
SUCCESS: Sent termination signal to the process "rclone.exe" with PID 20060.
ERROR: The process "rclone.exe" with PID 4988 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "rclone.exe" with PID 15100 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
test 2
and here are the 3 scripts,
start rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ x:
and
start /b rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ y:
and
rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ z:
and here is the output
C:\data\rclone\scripts\rr\mount>taskkill /im rclone.exe
SUCCESS: Sent termination signal to the process "rclone.exe" with PID 17400.
SUCCESS: Sent termination signal to the process "rclone.exe" with PID 9344.
ERROR: The process "rclone.exe" with PID 20704 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
i did some more testing.
it seems that when rclone.exe is executed, there is no conhost.exe created and as a result, rclone cannot see the ctrl+c/ctrl+break softkill as sent by taskkill
this process tree is showing the following command. start rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ x:
as you can see, there is a conhost.exe attachted to rclone.exe
this process tree is showing the following command rclone.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ z:
as you can see, there is NOT a conhost.exe attached to rclone.exe
rclone up to v1.49.3 was compiled with go1.12 but if you try the recently released rclone 1.49.4 that was compiled with go1.13 so may include the fix...
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
rclone.1.49.4.exe 21404 Console 1 24,148 K
C:\data\rclone\scripts\rr\mount>taskkill /im rclone.1.49.4.exe
ERROR: The process "rclone.1.49.4.exe" with PID 21404 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
rclone.1.49.4.exe 21404 Console 1 23,956 K
C:\data\rclone\scripts\rr\mount>sendsignal.exe 21404
Sending signal to process 21404...
CreateRemoteThread failed with 0x00000005.
StartRemoteThread failed with 0x00000005.
0x00000005 == Access is denied.
i found this https://golang.org/pkg/os/signal/
" On Windows a ^C (Control-C) or ^BREAK (Control-Break) normally cause the program to exit. If Notify is called for os.Interrupt, ^C or ^BREAK will cause os.Interrupt to be sent on the channel, and the program will not exit. If Reset is called, or Stop is called on all channels passed to Notify, then the default behavior will be restored."
well, if you want to run rclone.exe in the background, without a cmd window in the taskbar, then you would have a .cmd file with the line. start /b rclone.1.49.4.exe mount wasabiwest01:vserver03-bjv.h.vserver03.g.ampe01\ y:
in this case, it is not possible to send a ^c but it should be possible to send a ^break.
I find this unsightly to have a console window open when I run an exe and I don’t need to see any output. I couldn’t find this documented on any golang site. I can’t remember where I found it, but it is good to know:
Just add "-H=windowsgui" to your linker flags. Console window gone. You’re Welcome.