How do you run shell commands as foreground and background processes? Give an example for each.
时间: 2024-05-07 08:21:38 浏览: 79
Python2.x利用commands模块执行Linux shell命令
To run a shell command as a foreground process, simply type the command in the terminal and hit enter. The command will run in the foreground and the terminal will be blocked until the command completes. For example:
```
$ ls -l
```
To run a shell command as a background process, add an ampersand (&) at the end of the command. This will allow you to continue using the terminal while the command runs in the background. For example:
```
$ sleep 10 &
```
This command will run the "sleep 10" command in the background, and return control of the terminal to you immediately. The sleep command will run for 10 seconds in the background before completing.
阅读全文