Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

added a kill command in pxh console to kill the whole process including gz server #23881

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions platforms/posix/src/px4/common/px4_daemon/pxh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <poll.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

#include "pxh.h"

Expand Down Expand Up @@ -124,6 +125,9 @@ int Pxh::process_line(const std::string &line, bool silently_fail)
list_builtins(_apps);
return 0;

} else if (command == "kill") {
return shutdown_handler(0, nullptr);

} else if (command.length() == 0 || command[0] == '#') {
// Do nothing
return 0;
Expand Down Expand Up @@ -551,4 +555,18 @@ void Pxh::_tab_completion(std::string &mystr)
}
}

int Pxh::shutdown_handler(int argc, char *argv[])
{
printf("Force shutting down...\n");
fflush(stdout);

// Force kill all child processes
int ret = system("pkill -9 -f gz");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't necessarily want to kill gazebo everytime.

(void)ret; // Suppress warning about unused return value
printf("Killed gz...\n");
ret = system("pkill -9 -f px4");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong, why should px4 kill itself with pkill? Is there a reason we can't shutdown cleanly in the first place?

(void)ret; // Suppress warning about unused return value
return 0;
}

} // namespace px4_daemon
1 change: 1 addition & 0 deletions platforms/posix/src/px4/common/px4_daemon/pxh.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Pxh
*/
static void stop();

static int shutdown_handler(int argc, char *argv[]);
private:
void _print_prompt();
void _move_cursor(int position);
Expand Down
Loading