0

I am writing a ruby script in which I want to execute the android logcat -v time command in a child process and after some time kill the process (when the the parent is done doing xyz).

For example I have: childpid = Process.fork { adb -s <device-serial> logcat -c adb -s <device-serial> logcat -v time>/path-to-file/forkLog.log }

sleep(30)
    #parent do thing else here ...
Process.kill("SIGHUP", childpid)  #kill the child process

According to what I've read the adb logcat code is executed in another child sup-process, so when I try to do a Process.kill the childpid stops but its sub-process does not.

how do I kill the logcat -v time>forklog.log process from the parent process??

user1861040
  • 81
  • 1
  • 2

1 Answers1

0

Typically, when you're using fork to call a bash script, you'll want to use Kernel::exec() instead of Kernel::system() or Kernel::`

Process.fork{exec('adb -s <device-serial> logcat -c && adb -s  <device-serial> logcat -v time>/path-to-file/forkLog.log'}

The difference is that exec will replace the Ruby process with the shell script, while the other two will create a subprocess.

charredUtensil
  • 153
  • 1
  • 11
  • Thank you. I tried this but it does not seem to work adb might be running in another subprocess--- after I did some further reading – user1861040 Feb 01 '13 at 20:21
  • basically I need a way to kill all (great)grandchildren and then kill child in order for this to work... but how to do this? – user1861040 Feb 01 '13 at 20:22