How to restart a module with code?

I have a module defined as below. In the shell, I can run “myModule stop/start” to restart the module. Is there a way to do it with code (e.g., in a mavlink message, I want to restart myModule)? Thanks!

class myModule: public ModuleBase<myModule>, public ModuleParams, public px4::ScheduledWorkItem {
}

Looks like we may be able to send the command to the main px4 instance (server) via socket.

And the doc also mentions that. But I couldn’t find some example how to send such command from a client.

The server listens on a socket, to which clients can connect and send a command. The server then sends the output and return code back to the client

You can do system calls to run other commands.

I’ve just done that here: Add I2C driver launcher by julianoes · Pull Request #22047 · PX4/PX4-Autopilot · GitHub

And note that it also requires some px4board and defconfig changes. It’s all in the pull request.

Thanks for the reply, @JulianOes. Do you mean something like this?

system("/opt/px4/bin/px4-muModule stop");
system("/opt/px4/bin/px4-muModule start");

Oh, my PR is for the Pixhawks, so NuttX based. For SITL on Linux it might look somewhat like what you suggest, as long as you have the paths right.

Got it, thank you so much, @JulianOes!