I was following React Apollo tutorial, but had to stop at the point to ask me to run the server and app simultaneously. I tried to run the app first by 'yarn start' in the current directory and move to 'server' directory to run the server by 'yarn dev' after terminating the app, 'ctrl c', which isn't running two things at the same time.
What I Did
in apollo directory
yarn start
ctrl c
cd server
in server directory
yarn dev
How can I run the server(in server directory) and app(in apollo directory) at the same time? Thanks!
CodePudding user response:
In your terminal window there should be a button in the top right corner, this will open a new tab. You should be able to run both in separate tabs, I typically start the server first. Mine looks like this: enter image description here
CodePudding user response:
Simplest way in my opinion is:
program1 &
program2 &
This will run both program in the background.
If using this as a part of a script, you can use wait
as well.
You might find other commands useful:
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.
There are a few other options. To deeply understand this you need to be familiar with how processes work as a part of the OS.
See How do you run multiple programs in parallel from a bash script?, Using bg and fg with a given PID