Skip to content

Improve OS.kill()'s error handling and add a method is_process_running to check for running processes  #1679

Closed
godotengine/godot
#51682
@MikeSchulze

Description

Describe the project you are working on:
I'm working on a unit test plugin. It startes a test client in the background (hidden application)
The client comunicates over network connection with der server running by the plugin.
To run the test client i use the provided functionallity OS.excetute() with this arguments
[--no-window, -d, -s, res://addons/gdUnit/src/core/GdUnitClient.gd]
The client is closing/terminate by it self when all tests are done.
To manually stop a running test client i use the pid from OS.excetute() and send a kill OS.kill() to terminate the client.
So good so far ;)

Describe the problem or limitation you are having in your project:
When i stop a running test client with OS.kill() results into OK for a success terminated process.
But when the client is already terminatet i have no chance to check if the client still running or not.
e.g. when i try now OS.kill() on a already terminated process i got only an generic error Error.FAILED

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
To improve the OS.kill() it should return a better error

  • add to the Error enum PID_NOT_EXIST
  • replace the Error enum with and Error object where contains the error number and a human readable message

Add a new function to check if a process running by given PID

  • OS.is_process_running(<pid>) -> bool
    returns true when a process is running by given PID or false

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
With this better error handling on OS.kill() we can check if the process already terminated for better control flow.
With OS.is_process() we can verify if the process running or not.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
i found no way to check if an process is running by given PID

Is there a reason why this should be core and not an add-on in the asset library?:
This is a missing function on the OS class to manage spawned processes

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions