I would like to know how I can run two ongoing processes at the same time in Linux/bash. basically, I have a Node web server, and a MJPG-Streamer server. I want to run both these processes at once, but they are ongoing processes. I heard about running them as background processes, but I want them to be the same priority as a foreground process.
When you say priority, you probably mean the nice-level of the process. To quote Wikipedia:
nice is a program found on Unix and Unix-like operating systems such as Linux. It directly maps to a kernel call of the same name. nice is used to invoke a utility or shell script with a particular priority, thus giving the process more or less CPU time than other processes. A niceness of −20 is the highest priority and 19 or 20 is the lowest priority. The default niceness for processes is inherited from its parent process, usually 0.
Running a process in the background does not inflict on it's nice-level. It's entirely the same as when you're running it in the foreground.
So you can easily run your application/process in the background by invoking it with a trailing '&'-sign:
You can also send a foreground-process to the background, by pressing ctrl+z (pauses the execution) followed by bg+enter.
You can list running background-tasks with the command jobs.
To get it back to the foreground you must find out its job-ID with the jobs-command, and run fg [job-ID] (for example: fg 1)
Background tasks will send all their output to your shell. If you don't want to see their output, you'll need to redirect it to /dev/null:
my-server 1>/dev/null &
...which will redirect normal output into the void. Errors will still be visible.
If you want to run the two processes from the same console or xterm in the foreground, you could consider running them inside screen or tmux sessions, which are terminal multiplexers. The processes won't run under the same shell process then, but under separate shell processes.
E.g. using screen:
- Run the first process
Ctrl-a cto start a second shell session
- Start the second process
- Switch back and forth between the two subshells using
See screen manual for more info.