Nohup alternative - Running persistent scripts after closing adb

Viewed 3440

I'm having a problem keeping scripts running (in background) through ADB on my non-rooted Mate 10 after the phone has been unplugged.

I've tried to use the nohup command which has always worked for me with other Android devices, to no avail. I know that nohup only protects from SIGHUP and SIGQUIT signals and so the device might be sending a different signal to kill the process.

I have also tried spawning a child task which runs the script to try to 'hide' the spawned process and tried calling /system/bin/sh to spawn a shell within a shell which have both also failed.

Does anyone have some ideas on alternatives to nohup for non-rooted Android OS or any other ideas on how to solve this issue?

Edit: disown and screen are not present in the Mate 10's shell so they cannot be used.

1 Answers

there are several options:

disown

You can combine disown and & to push your script to the background

$ disown [your_command] &
[your_command] can be checked by the jobs command. Once typed you will 
$ jobs
[1]+ Running [your_command]

screen

Is a virtual terminal. Screen will keep running even if your session gets disconnected. When you reconnect to the server you can reconnect to the screen session and everything will be as if nothing happened.

link: gnu screen manual

background push

[your_command] &>/dev/null &

&>/dev/null redirects all the command output to a black hole.

& runs the process in the background.

Related