What does “program &” mean on the command line?

2019-03-07 04:32发布

I need to develop a client and server program with using sockets. My program should get port number from the command line. I saw an example which says "myprogram 2454 &".

I wonder what that & (ampersand) means there.

标签: shell unix
2条回答
唯我独甜
2楼-- · 2019-03-07 04:57

It means to start the process in the background. http://tldp.org/LDP/abs/html/x9644.html so that you may continue to use your shell session to run other programs. You can then use fg to "foreground" your process again.

查看更多
一纸荒年 Trace。
3楼-- · 2019-03-07 05:00

The ampersand (&) means that you want to run myprogram in background. This is normally used when you want to stay on your command-prompt and continue the work on the same session.

Example

somescript  &

will run the somescript shell script in background. You will get the prompt back on the next line. If you run somescript without & then the prompt may not appear back because somescript may take more time.

The best way is to run it in background with no hangups, in which case even of you loose your connection to the host the process keeps running on the UNIX or Linux host.

For example

nohup  somescript &

the jobs command will display the jobs running in background.

查看更多
登录 后发表回答