I have a script that takes a few seconds to complete. I would like to fork it into the
background, so that it continues to do its job, while allowing me to work with bash.
There are some workarounds such as forking in shell I guess, but I want to really
start the script, spawn a daemon, let it work there without me having to wait
on the commandline.
Now - there are some hints on the www but nothing that is really simple.
I guess what I need is some mini-daemon that does the job, while it allows
for me to continue to work with bash. Does anyone have some suggestions
or perhaps even has a script that does something like this?
Specifcally I would need the .rb file to output something, such as āforking
to backgroundā, and then immediately allow me to continue to work with
bash after that message. I know how to use Thread.new() but this still
requires an actively running .rb file; I need something more like fork/spawn
or Process daemon but ideally something that is SUPER simple. Ideally
something I could copy paste in a minimal way, even better if I would
NOT have to depend on any external gem that does it for me - I really
want this to be purely standalone in that .rb file as much as possible.
I donāt think thatās the answer. Say you want to make a professional software (or a huge game). You need to open a window in separate thread. Would you suggest your users / players to alias it? Thatās a bad practice. I would suggest the OP to use either Open3, or just use class Thread.
The .bash_aliases file is a extension of the .bashrc file. This file runs all processes that start on the user login level. Itās used so that people can add to this file without accidentally damaging or adding bad code to .bashrc
.rc_local controls all processes that start on the Boot level, or rather is the extension of the bootloader.
If you want a script to start when you log in under a user, or have different scripts begin under different users, you would use the .bashrc or itās user created softlink .bash_aliases. example, you want a Minecraft server to start when you log in, you would make your script and call it via . bashrc/.bash_aliases.
If you want your system to auto update under specific specs, you would make your script and run it under .rc_local.
Either case, if you need your script to run in a bg process, the kernal & is needed.
ruby /path/myscript.rb &
In script
ā&ā or system ā&ā
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.