Launching Tasks in the Foreground and Background
来源:互联网 发布:真实赛车3车辆数据排行 编辑:程序博客网 时间:2024/05/16 18:32
Launching Tasks in the Foreground and Background
Suppose you have a long-running task (for example, compiling a large program) that you need to run, but you also want to get some other work done. Linux lets you start a task in the background and keep on doing other things from the command prompt. By a dding the ampersand (&) to the end of any command, you can launch it in the background and get your command prompt back right away. For example,
cc hugepgm.c > outlist &
will start cc (the C compiler) as a background task, executing it in parallel with other tasks on your system.
Note: It's a good idea to redirect the output of background tasks to a file, as shown here, since the background task still shares the console with foreground tasks. If you don't, the background task will splash any output it might produce all over your screen while you're editing a file or typing another command.
If you start a long-running task and forget to add the ampersand, you can still swap that task into the background. Instead of pressing ctrl-C (to terminate the foreground task) and then restarting it in the background, just press ctrl-Z after the command starts, type bg, and press enter. You'll get your prompt back and be able to continue with other work. Use the fg command to bring a background task to the foreground.
You might wonder why you'd ever want to swap programs between the foreground and background, but this is quite useful if for example you're doing a long-running compile and you need to issue a quick command at the shell prompt. While the compilation is running, you could press ctrl-Z and then enter the bg command to put the compiler in the background. Then do your thing at the shell prompt and enter the fg command to return the compiler task to the foreground. The ctrl-Z trick also works with the Emacs text editor and the Pine email program. You can suspend either program and then return t o your work in progress with the fg command.
Of course, in the X Windows environment, all these unnatural gyrations are not necessary. Just start another shell window and run the other command there. You can watch both processes running in separate windows at the same time, and you don't have to w orry about adding ampersands, piping output to files, or keeping track of foreground versus background processes.
- Launching Tasks in the Foreground and Background
- Being productive in the background – background tasks
- Background Modeling and Foreground Detection -- SOBS
- Background Modeling and Foreground Detection -- GMM
- 背景建模与前景检测(Background Generation And Foreground Detection)
- 背景建模与前景检测(Background Generation And Foreground Detection)
- 背景建模与前景检测(Background Generation And Foreground Detection)
- 背景建模与前景检测(Background Generation And Foreground Detection)
- 背景建模与前景检测(Background Generation And Foreground Detection)
- 背景建模与前景检测(Background Generation And Foreground Detection)
- Running a Service in the Foreground
- Coloring the Console Application (AddingText and Background color in C#)
- Foreground Process&Background Process
- Working in the Background
- Launching and Viewing Processes in C#
- Code insight and other background tasks are disabled.
- 背景建模与前景检测之一(Background Generation And Foreground Detection)
- 背景建模与前景检测之二(Background Generation And Foreground Detection Phase 2)
- 安卓(android)的样式(style)和主题(theme)
- @代表“Objective-C”的标志,证明您正在使用Objective-C语言 Objective-C语言关键词,@property与@synthesize配对使用。 功能:让编译好器自动编
- FusionCharts Free中文开发指南 第七章--使用XML来创建和控制图形
- FusionCharts Free中文开发指南 第八章--FusionCharts Free和组合图XML
- linux音频alsa-uda134x驱动分析之二(时钟)
- Launching Tasks in the Foreground and Background
- 二分插入排序算法的C/C++实现
- FusionCharts Free中文开发指南 第九章--动态改变图形的类型和数据
- 有一个数组,各种数组出现次数的神组合……
- FusionCharts Free中文开发指南 第十章--FCF中的下钻
- PLAY2.0框架快速入门
- UITableView实现双击事件的方法
- c++ primer 13.4
- java中this的使用