Vishal Ladha
Vishal Ladha

Reputation: 221

Running two processes in parallel from makefile

I am trying to run both a server and client to run from a makefile:

target:

   ./server&
   ./client

The problem is that server& never returns the control back even though I assume it should run in the background. It keeps listening for client which is never invoked as the makefile does not seem to get the control back from server. How can I solve this issue?. without writing any additional target or scripts?

Upvotes: 22

Views: 22658

Answers (2)

sehe
sehe

Reputation: 392833

You should be able to do this by combining the commands on a single line:

target:
     ./server& ./client

Make hands commandlines to the shell ($(SHELL)) one line at a time.

Alternatively, you could define two independent targets:

target: run_server run_client

run_server:
     ./server
run_client:
     ./client

and run make with the -j option to make it parallelize build steps:

make -j2

This would not appear the most natural solution for launching your program (e.g. for test) but works best when you have large numbers of build rules that can be partly built in parallel. (For a little more control on make-s parallellization of targets, see also

.NOTPARALLEL

If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the ‘-j’ option is given. Any recursively invoked make command will still run recipes in parallel (unless its makefile also contains this target). Any prerequisites on this target are ignored.

Upvotes: 36

mikithskegg
mikithskegg

Reputation: 816

server runs in background. You may put in foreground using command fg. And then kill it with Ctrl-C

Or maybe this method: killall server

Upvotes: 2

Related Questions