# Rclone to respect a soft-kill termination

**URL:** <https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110>\
**Category:** Feature\
**Created:** [September 30, 2019, 8:21pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110 "2019-09-30T20:21:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [September 30, 2019, 8:21pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/1 "2019-09-30T20:21:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alfred](https://forum.rclone.org/user_avatar/forum.rclone.org/alfred/32/1164_2.png) [@alfred](https://forum.rclone.org/u/alfred)\
**Post date:** [September 30, 2019, 9:07pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/2 "2019-09-30T21:07:37Z")

</div>

Run as admin, maybe works

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [September 30, 2019, 9:20pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/3 "2019-09-30T21:20:25Z")

</div>

thanks for the suggestion but the command prompt that i am using to run the command has administrator privileges.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 1, 2019, 10:03am UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/4 "2019-10-01T10:03:54Z")

</div>

> [@asdffdsa](#):
>
> Reason: This process can only be terminated forcefully (with /F option).

It looks like that rclone would have to respond to the [WM\_CLOSE](https://stackoverflow.com/questions/51285503/how-to-handle-the-termination-request-sent-by-taskkill-in-windows) 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:

> <https://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows>

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 1, 2019, 4:06pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/5 "2019-10-01T16:06:46Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 1, 2019, 5:06pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/6 "2019-10-01T17:06:00Z")

</div>

in my testing, never once, did sendsignal.exe kill rclone.exe

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 1, 2019, 7:00pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/7 "2019-10-01T19:00:30Z")

</div>

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  
 ![image](https://forum.rclone.org/uploads/default/original/2X/1/11458cc6f455e285def2e6557c418ebc3f4804f8.png)

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

 ![image](https://forum.rclone.org/uploads/default/original/2X/3/32b3483276acc97effa0898da508291ffc12abf1.png)

seems to me that rclone.exe needs to implement this function call.

> **[SetConsoleCtrlHandler function - Windows Console](https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler?redirectedfrom=MSDN)**
>
> Adds or removes an application-defined HandlerRoutine function from the list of handler functions for the calling process.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 1, 2019, 9:21pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/8 "2019-10-01T21:21:49Z")

</div>

It looks like that has been added to go1.13 already: [https://github.com/golang/go/issues/7479](https://github.com/golang/go/issues/7479)

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...

Can you give it a go?

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 1, 2019, 9:41pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/9 "2019-10-01T21:41:49Z")

</div>

thanks for the update but no change in behavior,  
but i will look deeper into the link that you sent to me.

C:\data\rclone\scripts\rr\mount\>C:\data\rclone\scripts\rclone.1.49.4.exe --version  
rclone v1.49.4

- os/arch: windows/amd64
- go version: go1.13.1

C:\data\rclone\scripts\rr\mount\>tasklist /fi "imagename eq rclone.1.49.4.exe"

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).

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 1, 2019, 9:55pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/10 "2019-10-01T21:55:06Z")

</div>

i also tried sendsignal.exe and that did not work.

C:\data\rclone\scripts\rr\mount\>C:\data\rclone\scripts\rclone.1.49.4.exe --version  
rclone v1.49.4

- os/arch: windows/amd64
- go version: go1.13.1

C:\data\rclone\scripts\rr\mount\>tasklist /fi "imagename eq rclone.1.49.4.exe"

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.

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 1, 2019, 11:29pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/11 "2019-10-01T23:29:07Z")

</div>

i found this  
[https://golang.org/pkg/os/signal/](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."

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 2, 2019, 6:47am UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/12 "2019-10-02T06:47:06Z")

</div>

> [@asdffdsa](#):
>
> 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

rclone does intercept os.Interrupt and I think WinFSP does too. Does rclone quit OK if you press CTRL-C when you have it running in a CMD windows?

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 2, 2019, 2:27pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/13 "2019-10-02T14:27:01Z")

</div>

yes,

based on my testing, rclone will close ok in the following cases.

1. when run inside a cmd window.
2. when run using `start`
3. when run using `start /w`

rlcone will not close ok when run as a standalone program.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 2, 2019, 3:02pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/14 "2019-10-02T15:02:04Z")

</div>

> [@asdffdsa](#):
>
> rlcone will not close ok when run as a standalone program.

Ah... How are you running rclone as a standalone program? I would have thought it would open a CMD windows if you just double click on it.

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 2, 2019, 6:19pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/15 "2019-10-02T18:19:20Z")

</div>

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.

tho i am not clear as to how to send the signal?

on windows, we use the taskkill.exe to kill apps.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 2, 2019, 7:18pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/16 "2019-10-02T19:18:57Z")

</div>

> [@asdffdsa](#):
>
> in this case, it is not possible to send a ^c but it should be possible to send a ^break.

CTRL-Break should stop rclone according to the go docs.

> [@asdffdsa](#):
>
> tho i am not clear as to how to send the signal?

No me neither...

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 2, 2019, 7:27pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/17 "2019-10-02T19:27:44Z")

</div>

in any event, taskkill.exe is the standard way to kill since windows xp.  
most strange the rclone.exe is creating this problem.

when there is cmd window that rclone is running inside of, it could be the ^c is being sent to the cmd window, which then kills all sub-processes.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 3, 2019, 7:01am UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/18 "2019-10-03T07:01:40Z")

</div>

One thing to try is building rclone like this

```
go build -ldflags "-H windowsgui"

```

Can you try this? I'm not 100% sure what will happen!

---

<div class="post-metadata">

**Author:** ![asdffdsa](https://forum.rclone.org/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@asdffdsa](https://forum.rclone.org/u/asdffdsa)\
**Post date:** [October 3, 2019, 1:46pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/19 "2019-10-03T13:46:03Z")

</div>

i program in python, no nothing about go.

and in doing research on the flag windowsgui, i found this link and other links stating the same thing.

`https://lukeeckley.com/post/useful-go-build-flags/`

Windows Executable Without Console Window

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.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 3, 2019, 4:41pm UTC](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/20 "2019-10-03T16:41:31Z")

</div>

> [@asdffdsa](#):
>
> i program in python, no nothing about go.

Download the rclone source, install go then run that command to build your own rclone.exe `go build -ldflags "-H windowsgui"` is what is required.

I can do it for you but I don't have access to a Windows machine right now!

[Next page](https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110.md?page=2)
