question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Stop-Process does not issue SIGTERM as expected.

See original GitHub issue

Steps to reproduce

taskkill /IM "App With Tray Icon.exe"

Without moving mouse, tray icon disappears from tray immediately.

Stop-Process "App With Tray Icon"

Without moving mouse, tray icon is stays visible. Additionally, starting the process again will display a duplicate icon, the old one disappears when hovering over it.

Expected behavior

Stop-Process by default should be SIGTERM, graceful. SIGKILL should only be used after timeout or -FORCE is used.

Actual behavior

The old tray icon stays visible because app is killed. (This is not actually PowerShell specific, but a technical caveat when processes are killed.)

Workaround

Use taskkill in place of stop-process for processes that have tray icons.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.20215
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:55 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
manokaracommented, Sep 4, 2022

I’m on Windows with PowerShell 7.1.5. This behavior is quite unintuitive, because there is a -Force switch but Stop-Process always acts as if it was on, killing a process without mercy instead of gracefully shutting it down. I’ve noticed this also happens with Task Manager - it doesn’t give you an option to request a process to terminate, allowing for cleanup routines to be run. Being mostly a Linux user, I’m used to SIGTERMing processes and only SIGKILLing them as a last resort. Seems like SIGKILL is the default expected behavior on Windows.

In my use case, I’m dealing with console processes on a CI deployment pipeline so CloseMainWindow() doesn’t apply. Using taskkill instead as OP mentioned works as expected.

1reaction
iSazonovcommented, Feb 4, 2021

Even if we address all the problems above - i.e. if we truly give all all targeted processes a chance to terminate gracefully - enforcing (ultimate) termination should (a) be opt-in and (b) can, as stated, only be achieved by waiting for actual termination based on a timeout, given that SIGTERM / CTRL_CLOSE_EVENT handlers can refuse to terminate in response to a request.

I believe we should do the cmdlet too smart and complex. It is currently impossible to send an event or signal to a process so that it terminates gracefully.

The suggestion is to just add such a feature - just send the signal and nothing else.

All other smart things the user can do himself (or we can add later after receiving feedback).


We can implement this on Unix too https://stackoverflow.com/questions/41041730/net-core-app-how-to-send-sigterm-to-child-processes

<div>Stack Overflow</div><div>.net-core app: how to send SIGTERM to child processes?</div><div>Is it possible for .net-core app running on Linux to send SIGTERM signal to a child process?

We’re thinking to port our .net app to .net-core and run it on Linux, to avoid current signal implement…</div>

Read more comments on GitHub >

github_iconTop Results From Across the Web

SIGTERM not working occasionally
The problem with this is it means the process cannot react and do whatever little things it needs to do before shutting down....
Read more >
In what order should I send signals to gracefully shutdown ...
Given that the default signal sent by kill is SIGTERM , I would expect it is the most-commonly expected signal for graceful shutdown...
Read more >
Inconsistent exitcode for terminated child processes on ...
I think that having results consistent with `os.kill(,SIGTERM)` would be desirable even if that means non-negative values. I'm willing to post a ...
Read more >
Why SIGTERM signal does not work for process group?
I want to send SIGTERM signal to jboss when my script was killed, terminated or interrupted. But above code does not terminate JBoss....
Read more >
Linux Graceful Termination | Exit code 143, Signal 15
Problem : NGINX does not perform graceful termination on SIGTERM. If you are using the official NGINX Ingress Controller, when the controller pod...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found