Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

bash - 如何在bash上同时运行2个命令(How to run 2 commands on bash concurrently)

I want to test my server program,(let's call it A) i just made.

(我想测试我的服务器程序,(我叫它A)。)

So when A get executed by this command

(所以当A被这个命令执行时)

$VALGRIND ./test/server_tests 2 >>./test/test.log

,it is blocked to listen for connection.After that, i want to connect to the server in A using

(,它被阻止侦听连接。之后,我想使用)

nc 127.0.0.1 1234 < ./test/server_file.txt

so A can be unblocked and continue.

(因此A可以被解除阻止并继续。)

The problem is i have to manually type these commands in two different terminals, since both of them block.

(问题是我必须在两个不同的终端中手动键入这些命令,因为它们都阻塞了。)

I have not figured out a way to automated this in a single shell script.

(我还没有找到一种在单个shell脚本中自动执行此操作的方法。)

Any help would be appreciated.

(任何帮助,将不胜感激。)

  ask by Van Teo Le translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use & to run the process in the background and continue using the same shell.

(您可以使用&在后台运行该过程,然后继续使用相同的shell。)

$VALGRIND ./test/server_tests 2 >>./test/test.log &
nc 127.0.0.1 1234 < ./test/server_file.txt

If you want the server to continue running even after you close the terminal, you can use nohup:

(如果您希望服务器即使在关闭终端后仍能继续运行,则可以使用nohup:)

nohup $VALGRIND ./test/server_tests 2 >>./test/test.log &
nc 127.0.0.1 1234 < ./test/server_file.txt

For further reference: https://www.computerhope.com/unix/unohup.htm

(有关更多参考: https : //www.computerhope.com/unix/unohup.htm)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...