首页 > 解决方案 > 如何在 Linux 终端中有两个正在运行的进程?(Linux 命令)

问题描述

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

我做了什么

在阿波罗目录

纱线开始

ctrl + c

光盘服务器

在服务器目录中

纱线开发

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

标签: linuxcommand-linegraphqlreact-apollo

解决方案


我认为最简单的方法是:

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.

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

请参阅如何从 bash 脚本并行运行多个程序?,使用给定 PID 的 bg 和 fg


推荐阅读