Resources:
- https://www.rubyguides.com/2018/12/ruby-system/
- https://medium.com/zendesk-engineering/running-a-child-process-in-ruby-properly-febd0a2b6ec8
- https://stackoverflow.com/questions/29845778/starting-a-process-and-killing-it-from-ruby-on-rails-app-without-leaving-zombie
- Executing and killing ruby parallel background jobs
The child process can exit using Kernel.exit! to avoid running any at_exit functions. The parent process should use Process.wait to collect the termination statuses of its children or use Process.detach to register disinterest in their status; otherwise, the operating system may accumulate zombie processes.
To Be Tested
def start
@pid = IO.popen("sleep").pid
# @pid = fork { `sleep` }
end
def stop
Process.kill(9, @pid)
Process.wait(@pid)
end
From article
returns the output of the command
`ls`
%x|ls|
returns boolean if the command is successful
- true (command worked)
- false (command errrors out)
- nil (command not found)
system("ls")
This will run ls on another process & display its output
pid = fork { exec("ls") }
Process.wait(pid)
From article
To Do
To Do
From article
r = IO.popen("irb", "r+")
r.write "puts 123 + 1\n"
3.times { puts r.gets }
r.write "exit\n"