How do you run multiple programs in parallel from a bash script?

前端 未结 15 1273
眼角桃花
眼角桃花 2020-11-22 06:31

I am trying to write a .sh file that runs many programs simultaneously

I tried this

prog1 
prog2

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 07:03

    If you're:

    • On Mac and have iTerm
    • Want to start various processes that stay open long-term / until Ctrl+C
    • Want to be able to easily see the output from each process
    • Want to be able to easily stop a specific process with Ctrl+C

    One option is scripting the terminal itself if your use case is more app monitoring / management.

    For example I recently did the following. Granted it's Mac specific, iTerm specific, and relies on a deprecated Apple Script API (iTerm has a newer Python option). It doesn't win any elegance awards but gets the job done.

    #!/bin/sh
    root_path="~/root-path"
    auth_api_script="$root_path/auth-path/auth-script.sh"
    admin_api_proj="$root_path/admin-path/admin.csproj"
    agent_proj="$root_path/agent-path/agent.csproj"
    dashboard_path="$root_path/dashboard-web"
    
    osascript <

提交回复
热议问题