Run parallel multiple commands at once in the same terminal

前端 未结 6 803
礼貌的吻别
礼貌的吻别 2020-11-28 19:15

I want to run a few commands, each of which doesn\'t quit until Ctrl-C is pressed. Is there something I can run to run all of them at once, and Ctrl-C will quit them all? Th

6条回答
  •  天命终不由人
    2020-11-28 19:28

    It can be done with simple Makefile:

    sleep%:
            sleep $(subst sleep,,$@)
            @echo $@ done.
    

    Use -j option.

    $ make -j sleep3 sleep2 sleep1
    sleep 3
    sleep 2
    sleep 1
    sleep1 done.
    sleep2 done.
    sleep3 done.
    

    Without -j option it executes in serial.

    $ make -j sleep3 sleep2 sleep1
    sleep 3
    sleep3 done.
    sleep 2
    sleep2 done.
    sleep 1
    sleep1 done.
    

    You can also do dry run with `-n' option.

    $ make -j -n sleep3 sleep2 sleep1
    sleep 3
    sleep 2
    sleep 1
    

提交回复
热议问题