繁体   English   中英

Makefile-服务器后如何同时运行客户端?

[英]Makefile - How to run concurrently clients after server?

当前,我通过共享内存使用IPC来做一个客户端-服务器程序,当用make运行此程序时,我有一个小问题,我想运行服务器并在一个make目标中同时运行3个客户端,但不能运行,但使用2个针对它的目标。 有人可以帮我弄这个吗? 谢谢!

这对我有用的代码:

OPT_GCC = -std=c99 -Wall -Wextra
#compiler options and libraries for Linux
OPT = -D_XOPEN_SOURCE=700
LIB = -lrt -lpthread

CLIENTS = 3
MFLAGS = -j$(CLIENTS)

all: client server

client: mediasharingclient.c
    gcc $(OPT_GCC) $(OPT) -o client mediasharingclient.c $(LIB)

server: mediasharingserver.c
    gcc $(OPT_GCC) $(OPT) -o server mediasharingserver.c $(LIB)

run_server: server
   ./server ../sample1/send-order.txt&

run_clients: client1 client2 client3

client1:
    ./client 1 client1

client2:
    ./client 2 client2

client3:
    ./client 3 client3

clean:
   rm -f client server

我这样做: make run_servermake run_clients -j3

为了在不更改客户端或服务器实现的情况下完成这项工作,我们将不得不假设服务器将在固定的时间内(例如2秒)准备就绪:

OPT_GCC = -std=c99 -Wall -Wextra
#compiler options and libraries for Linux
OPT = -D_XOPEN_SOURCE=700
LIB = -lrt -lpthread

all: client server

client: mediasharingclient.c
    gcc $(OPT_GCC) $(OPT) -o client mediasharingclient.c $(LIB)

server: mediasharingserver.c
    gcc $(OPT_GCC) $(OPT) -o server mediasharingserver.c $(LIB)

run_server: server
    ./server ../sample1/send-order.txt &
    sleep 2

run_clients: client1 client2 client3

client1: client run_server
    ./client 1 client1

client2: client run_server
    ./client 2 client2

client3: client run_server
    ./client 3 client3

clean:
    rm -f client server

并使用make -j run_clients运行它。 每个客户端对run_server的依赖关系确保客户端目标在休眠和启动服务器时不会与run_server目标并行运行。

其他选择是让客户端反复尝试几秒钟,或者让服务器派生到后台并在准备好接受连接时终止(然后不要从Makefile在后台运行它)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM