So that the program returns immediately on the command line, so it is not tied to the shell that launched it

Some programs return immediately after starting from the command line, for example Firefox. Most utilities (and all the programs I wrote) are tied to the shell that created them. If you control - with the command line, the program is dead.

What do you need to add to the program or shell script to get reverse-immediate behavior? I guess I'm asking two questions: one for shell scripts and one for general if they are different. I would be particularly interested to know if there is a way to get an executable jar for this.

I am almost embarrassed to ask about this, but I cannot find the answer myself.

Thanks!

+4
source share
4 answers

For an executable program (as opposed to a shell script) on Linux / Unix, use fork () and exec (), and then exit the parent process, which will return to the shell. For more information, see the manual pages or a page, for example, http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html .

+2
source
start cmd 

on windows

 cmd & 

on * nux

Here we substitute

 cmd = java -jar JarFile.jar 

In * nux, the fg and bg commands are also your friends ...

+6
source

You need to basically develop the process or create a new thread (or pretend)

in * nux you can do this with & after a command like this /long/script & , or on Windows you can create a BATCH file that executes your processes and then exits (this is done naturally).

NOTE. There is no particular way to refer to this process after you fork it, basically just ps for the process list. if you want to see what this process is doing, look with screen (another linux command), which will start a session for you and allow you to "reconnect" to the screen.

To do this, install the screen ( sudo apt-get install screen or yum install screen ). then enter screen to create a new session (note this will look like you didn’t do anything). then run /long/command (without & ), then press CTRL + A + D (at the same time) to disconnect from it (it still works!). then when you want to reconnect, enter screen -r .

Also, find the checkboxes in any help message that allows you to do this without using the above options (for example, in synergy you can say synergy --background )

+3
source

A shell script consisting only of:

 your_prog_or_script & 

Launches the target and exits immediately. You can add nohup at the beginning of this line to continue if the shell is complete.

+3
source

Source: https://habr.com/ru/post/1299399/


All Articles