之前在csdn上搜索,提示用gnome-terminal指令,但是发现怎么都不好使。于是找到一种解决方案。
#!/bin/bash
echo "the first one"
./hello fork &
sleep 10
echo "the second one"
./hello
只要在可执行程序后添加"fork &"即可,测试两个程序同时执行。
测试程序
#include<iostream>
#include <unistd.h>
using namespace std;
int main(){
cout<<"hello"<<endl;
sleep(10);
}
结果:
the first one
the second one
hello
hello
fork 后不加 &,会等待第一个程序执行结束再执行第二个程序。
测试结果
the first one
hello
the second one
hello