4

I'm trying to learn a bit or 2 about process communication under Linux, so I wrote 2 simple C programs that communicate with each other.

However, it's a bit annoying to have to run them manually every single time, so I'd like to know is there a way to make a program that will run them both, something like this:

./runner program1 program2

I'm using latest Ubuntu and Bash shell.

5 Answers 5

4

run.sh script

#!/bin/sh
./program1 & 
./program2 &

run command:

$sh run.sh
Sign up to request clarification or add additional context in comments.

Comments

4

This line will do (in Bash):

program1 & program2 &

If you want to record the output:

program1 >output1.txt & program2 >output.txt &

If you want to run the commands in two separate terminals:

xterm -e program1 & xterm -e program2 &

Comments

2

Why not use this:

./program1;./program2

or

./program1 &;./program2 &

I don't know why somebody thinks it's not useful,but it really works.

Surely you can write a script,but what's the content of the script?Still the same thing.

And you can change it at once with no need to open the script first.

Comments

0

Just write a shell script to do what you want -- you don't need to use a C program to run a C program.

Comments

0

Do do exactly what you asked, first created a file called runner which will be the shell script.

#!/bin/bash

for arg in $@
do
$arg & 
done

$@ in bash is an array of all the arguments passed to the script, this makes the script no restricted to only launching 2 programs. Note any programs your launch with this scripts need to be on the $PATH or passed to the script as ./program1.

./runner ./program1 program2 

In the example program1 is not on the $PATH but program2 is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.