不同提示下运行不同进程的Makefile

Makefile that runs different processes in different prompts

我正在创建一个运行 process manager.c 和另一个进程 supermarket.c 的 Makefile。我想知道是否可以通过为每个文件打开一个 shell window 的方式来做到这一点,因为目前,我在同一个提示中得到了两个进程的输出并且它是我很困惑。

这是我的 Makefile:

all: manager supermarket

manager: manager.c
    $(CC) $(CFLAGS) $(THREADS) -o manager manager.c

    
supermarket: supermarket.c
    $(CC) $(CFLAGS) $(THREADS) -o supermarket supermarket.c


test2:  
    @echo [+] Starting Manager process...
    @./manager & echo $$! > m.PID
    @echo [+] Manager is running...
    @echo [+] Starting Supermarket process...
    @./supermarket 6 50 3 200 100 20 & echo $$! > sm.PID
    @echo [+] Supermarket is running...
    @sleep 25
    
    if [ -e m.PID ]; then \
        echo [+] Sending SIGHUP to Manager process...; \
        kill -1 $$(cat m.PID) || true; \
        echo [+] Manager waiting Supermarket to close...; \
        while sleep 1; do ps -p $$(cat sm.PID) 1>/dev/null || break; done; \
    fi;
    
    @rm m.PID
    @rm sm.PID
    @echo
    @echo
    @./analisi.sh $(LOG_FN)
    @echo
    @echo

运行 从 Makefile 中分离出终端是相当有问题的,因为它与 make 的一般流程接口不佳。一个更好的解决方案可能是让每个进程将其结果输出到一个日志文件,然后单独启动一个 xterm 或者你对每个文件有什么 运行 tail -f 来满足你的交互需求。

all: manager supermarket

manager: manager.c
    $(CC) $(CFLAGS) $(THREADS) -o manager manager.c

supermarket: supermarket.c
    $(CC) $(CFLAGS) $(THREADS) -o supermarket supermarket.c


test2:  
    ./manager >manager.log 2>&1 & \
    echo $$! > m.PID
    ./supermarket 6 50 3 200 100 20  >supermarket.log 2>&1 & \
    echo $$! > sm.PID

    sleep 25

    cat m.PID sm.PID | xargs kill -1 
    wait $$(cat m.PID sm.PID)
    rm -f m.PID sm.PID

    ./analisi.sh $(LOG_FN)

真的,不要乱扔你的 Makefile@(如果你不想看到发生了什么,你可以 运行 和 make -s)并可能减少人类可读的状态更新量。