Just add Process.wait(pid_logcat)
after your code.
Kill a Ruby child process when another Ruby child process has completed
-
06-03-2022 - |
Question
I'm trying to use Ruby to write a script to run monkey test on the Android app. I'm stuck with 1.8 Ruby and can't use spawn.
See below code for detail. For some reasons, the logcat
process will continue to run even after the monkey
process has completed. I had used Process.wait()
for wait for monkey
process to completed before killing the logcat
process, but it doesn't kill it. Am I not using the fork
properly?
Thanks.
pid_logcat = fork do
puts "Enter capturing logcat"
system("adb shell logcat | tee logcat.log")
end
pid_monkey = fork do
puts "Running monkey script"
system("adb shell monkey -p TestApp --throttle 200 -v 1000000 | tee Monkeylog.txt")
end
Process.wait(pid_monkey)
Process.kill("KILL", pid_logcat)
EDITED 1
I can confirm that adb
does spawn another process which is outside of ruby's control, what should I do now? Process.kill('HUP', -Process.getpgid(pid_logcat))
won't work because that will kill the parent process too (the ruby process forking this)
EDITED 2
exec()
also doesn't seem to work on pid_logcat
forked process.
La solution