Run process in background on Linux
Linux is a powerful operating system that provides users with a wide range of features and capabilities. One of the most useful features of Linux is the ability to run processes in the background, allowing users to continue working on other tasks without interruption. In this blog post, we will explore how to run a process in the background in Linux.
Simple background process
jobs to see background PID
Switch between foreground and background
Ctrl - Z
Process suspended, and return to the terminal
Check background process
Switch to background process
fg <job No.>
Let background process run in the background
bg <job No.>
Stop background process
kill %<job No.>
Run a background process and keep it running after logout
For example, a program that continuously outputs test.sh, as follows
while : do echo hello sleep 1 done
hope to continue to execute after closing the terminal
nohup ./test.sh &
The default program output is in the
Exit the terminal and log in again to check the process
ps aux | grep test.sh
kill the process, use
kill + process number
yum install screen apt install screen
screen, enter a new virtual terminal, and execute the task.
Detach the current
<Ctrl> + <A>, <D>
See all background terminals
Resume the last closed terminal
Running a process in the background is a useful feature that can help you multitask more efficiently on your Linux system. In this blog post, we explored three different methods for running processes in the background: using the & operator, using the nohup command, and using the screen command. With these methods, you can run processes in the background and continue working on other tasks without interruption.
Small world. Big idea!
- Welcome to visit the knowledge base of SRE and DevOps!
- License under CC BY-NC 4.0
- No personal information is collected
- Made with Material for MkDocs and generative AI tools
- Copyright issue feedback me#imzye.com, replace # with @
- Get latest SRE news and discuss on Discord Channel