If you want to bring it back to the foreground, use the fg command. When it is done, the shell will send us a notice.
+ 4836 Running /usr/libexec/locate.updatedb &Īt this point, we have interactive control, the script is running in the background, and we can do something else while it finishes. You don't need to give it a job number if there is only one background job. The bg command tells BASH to run the specified job number in the background. That can be fixed by using the bg command. Now we have control of the terminal back, but the script we started is currently not running. + 4836 Suspended /usr/libexec/locate.updatedb To check the status of the all background jobs, use the jobs command with the -l (list) switch: This means job number 1 has been stopped and shows the associated command. The Ctrl-Z sequence pushes the foreground job into the background, pauses it, and gives control back to you. You can force it into the background by using Ctrl-Z. The script is running in the foreground of the interactive shell. Since it takes a long time to run, you will be unable to run any other commands until it finishes. Note: if run as a regular user, it won't be able to scan all directories, so it should really be run as root. The Mac command for updating the locate database is a C shell script named /usr/libexec/locate.updatedb. It doesn't search inside files like spotlight, it only looks at file names. It lets you quickly find files based on a partial file name. As an aside, the locate database came to the Mac from the BSD world where there was no spotlight. Again, say you have logged into a remote computer using secure shell and you start a long running job, such as compiling a large program from source, or updating the locate database. Here is a scenario where job control can help get your work done a little faster. Yes, you can always open another terminal on your computer and establish a second secure shell connection, but that may be more trouble than it's worth. What about times when you are connected to remote Mac (or Linux or Unix) computer with secure shell? Now, you are back to the single interactive shell and the job control commands can be of assistance. You can also copy and paste information between them.
The beauty of this solution is that you can see both display windows at the same time and monitor what is happening.
Since the advent of the GUI, one solution to running multiple shell commands at a time is to open more than one terminal window.
Examples in this article were run on Mac OS 10.4.10. These are all shell builtins, meaning they are commands built into and handled by BASH itself instead of being external programs, like the top program. The commands I want to focus on are bg (background), fg (foreground), and jobs. In the age of multi-homed multi-core Macs, not so killer, but there are certain situations where it can still be useful.
In the age of serial connected dumb terminals, this was a killer feature. The BASH shell has a feature called job control that allows you to run and manage multiple processes from a single interactive prompt.