简体   繁体   中英

Windows process exit codes in the event of term signals

In Unix/Linux environments it is quite easy to determine whether a program has exited due to a signal interrupt (sigterm), and which signal interrupt.

It is possible to determine (programmatically using API's or exit code) whether a windows program has exited due to a signal (sigkill, from powershell as example)?

To expand on my question:

  • Is it possible for a user to kill an application from eg the task manager, or from powershell? ??
  • If an application is unresponsive and the OS kills the application, what would its exit code be? ??

Windows has "many, many" error codes, and I would want to know which ones relate to process management only.

Kind regards,

No there is not since Windows does not have signals. Terminating a process happens using the TerminateProcess API.

TerminateProcess does all the caller to pass in an exit code, but there is no documented value for what powershell or the Task Manager would set this to.

Windows does not define any process exit codes, an application may use any exit codes that it wants. There are no "process management error codes" to check for.

To answer your questions directly:

Is it possible for a user to kill an application from eg the task manager, or from powershell?

Yes it is. You can kill a process from Task Manager, powershell uses kill or Stop-Process or using taskkill from the command line.

If an application is unresponsive and the OS kills the application, what would its exit code be?

There is no guaranteed exit code for this. Windows probably sets it to something, but that is an implementation detail and is open to change between different versions of Windows.

Is it possible for a user to kill an application from eg the task manager, or from powershell.

Yes.

If an application is unresponsive and the OS kills the application, what would its exit code be.

The OS will not kill an application. A user may elect to do so, sometimes at the prompting of the OS. In that case, the exit code is not defined.


When an application terminates normally, it sets its exit code. Exit codes are process specific. The only convention is that 0 means success. After that it's a crap shoot.

When an application is terminated forcibly by TerminateProcess , the terminator passes the exit code in the call to TerminateProcess .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM