【问题标题】:How to have two running processes in Linux terminal? (Linux command)如何在 Linux 终端中有两个正在运行的进程? (Linux 命令)
【发布时间】:2021-11-18 01:43:24
【问题描述】:

我正在学习 React + Apollo 教程,但不得不停下来要求我同时运行服务器和应用程序。我尝试先通过当前目录中的“yarn start”运行应用程序,然后在终止应用程序“ctrl + c”后移动到“server”目录以通过“yarn dev”运行服务器,该应用程序没有运行两件事同时。

我做了什么

在阿波罗目录中

纱线开始

ctrl + c

光盘服务器

在服务器目录中

纱线开发

如何同时运行服务器(在服务器目录中)和应用程序(在 apollo 目录中)?谢谢!

【问题讨论】:

  • 我想到了许多选项(后台作业、屏幕、tmux 等),但为什么不直接打开第二个终端并在那里运行第二个命令呢?
  • @knittl 谢谢。我不知道我能做到这一点。

标签: linux command-line graphql react-apollo


【解决方案1】:

在你的终端窗口右上角应该有一个按钮,这将打开一个新标签。您应该能够在单独的选项卡中运行这两个选项卡,我通常首先启动服务器。 我的看起来像这样: enter image description here

【讨论】:

    【解决方案2】:

    我认为最简单的方法是:

    program1 &
    program2 &
    

    这将在后台运行这两个程序。 如果将其用作脚本的一部分,您也可以使用 wait

    您可能会发现其他有用的命令:

    jobs # prints all jobs running in the background
    fg [job_id] - foreground, brings the program to the front.
    bg [job_id] - background, sends a program to the background.
    CTRL+Z - suspends a job running in the front. You'll be able to see it when running jobs.
    

    还有其他一些选项。要深入理解这一点,您需要熟悉进程作为操作系统的一部分是如何工作的。

    How do you run multiple programs in parallel from a bash script?Using bg and fg with a given PID

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-23
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      相关资源
      最近更新 更多