superl2
superl2

Reputation: 13

Run multiple commands at once in RootTools/RootShell?

I'm using the RootTools library, and I need to execute two commands. The first one runs a binary, the second sends SIGINT to it, to kill it.

RootTools (as far as I know) can only have one root shell open at a time, so commands can only be executed one by one. This is a problem, because I have no way to stop my binary after I've ran it.

How can I do any of the following things?

I need to use RootTools because it's the only way for me to read standard output from my program. If there's another way to do that, though, please comment.

Upvotes: 0

Views: 265

Answers (1)

MaxChinni
MaxChinni

Reputation: 1216

Do you think you can concat the commands?

Let's say I want to launch a find command, but if it takes 5 seconds, I want it to stop:

find / & sleep 5 && kill $!

We can get a better suited one liner, too (i.e. ignore standard error, kill only if needed etc.).

You could also just store the PID and kill it later (be careful, if the daemon stopped to run, his PID can be reused by the OS):

  1. run the daemon in a root shell

    my-daemon >/dev/null & echo "PID: $!"
    
  2. parse the output in Java and store the PID (SharedPreferences?)

    var pid = outputLine.split(" ")[1]
    
  3. later on, stop the daemon with a root shell

    kill <pid>
    

Upvotes: 0

Related Questions