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?
To start GNU Make in parallel mode it's enough to specify either the -j or --jobs option on the command-line. The argument to the option is the maximum number of processes that GNU Make will run in parallel. For example, typing make --jobs=4 will allow GNU Make to run up to four subprocesses in parallel.
The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With