Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Terminating gazebo leaves many zombie processes #2738

Closed
erlingrj opened this issue Jan 28, 2025 · 2 comments · Fixed by #2747
Closed

Terminating gazebo leaves many zombie processes #2738

erlingrj opened this issue Jan 28, 2025 · 2 comments · Fixed by #2747
Labels
bug Something isn't working good first issue Good for newcomers help wanted We accept pull requests!

Comments

@erlingrj
Copy link
Contributor

erlingrj commented Jan 28, 2025

Environment

  • OS Version: Ubuntu 24.04
  • Source or binary build: Binary build, version 8.8.0

Description

  • Expected behavior: When sending a signal, e.g. SIGTERM or SIGKILL to the process launching gz sim ..., I expect all spawned processes and threads to be cleaned up.
  • Actual behavior: GUI keeps running, and several threads and processes in the background keeps running.

Steps to reproduce

E.g. compiling this simple program:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>

int main() {
    pid_t pid = fork();
    if (pid == -1) {
        // Fork failed
        printf("Fork failed\n");
        exit(1);
    } else if (pid == 0) {
      // Child process 
      system("gz sim simple_robot.sdf -r");
      exit(0);
    } else {
      // Parent process
     sleep(3);
      kill(pid, SIGTERM);
     wait(NULL);
    }
}

Assuming a model file called simple_robot.sdf is in the current working directory, then executing it will lead to the GUI remaining open and a bunch of other threads running in the background. I have spent a lot of time trying to kill all dependent and child processes, but with no luck.

Another, simpler way to reproduce is to just launch the process from a terminal, in the background and then try to kill it:

gz sim simple_robot.sdf -r &
kill $!
@erlingrj erlingrj added the bug Something isn't working label Jan 28, 2025
@azeey
Copy link
Contributor

azeey commented Jan 29, 2025

I think this is because his piece of code in cmdsim.rb catches only SIGINT. Updating to include SIGTERM could fix it

gz-sim/src/cmd/cmdsim.rb.in

Lines 556 to 560 in 689ee9d

Signal.trap("INT") {
self.killProcess(guiPid, "Gazebo Sim GUI", 5.0)
self.killProcess(serverPid, "Gazebo Sim Server", 5.0)
return 1

Can you give it a try? If it works, do you mind opening a PR?

@azeey azeey added help wanted We accept pull requests! good first issue Good for newcomers labels Jan 29, 2025
@azeey azeey moved this from Inbox to To do in Core development Jan 29, 2025
@erlingrj
Copy link
Contributor Author

Thanks for your suggestion, it now works! I have submitted a PR with the fix here #2747

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted We accept pull requests!
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants