开发者

How do I launch a program inside a shell script and have the shell script continue, even though the program remains open

I am using bash on Ubuntu. I would like to have a shell script open a program 开发者_开发技巧and continue on to the next line of the shell script, even though the program has not terminated.


Adding an & to a command places it in background.

example:

/path/to/foo    
/path/to/bar     # not executed untill foo is done


/path/to/foo &    # in background
/path/to/bar &    # executes as soon as foo is started

Read more about job-control here and here


Use something like this (my-long-running-process &) . This will launch your script as a separate process in the background.


You must run the process in the background, but you must enable job-control first. Otherwise, you cannot kill or bring the process to foreground if desired.

To enable job-control, execute:

set -m

To run some task in the background, execute:

task &

To manipulate the background task, use the jobspec syntax (%[n]). For example, to kill the last launched process, execute:

kill %

Note that enabling job-control is required only if you're actually running a script (as stated in the question). If running interactively, job-control is already enabled by default.

The manpage for bash has much more information in the JOB CONTROL section.


http://ubuntuforums.org/showthread.php?t=1657602

It looks like all you have to do is add a & at the end of the line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜