预计阅读本页时间:-
Background Jobs and Priorities
Background jobs can save you a lot of thumb-twiddling time. Just remember that such jobs eat up lots of system resources like memory and the processor (CPU). Just because you're running several jobs at once doesn't mean that they will run faster than they would if run sequentially—in fact, performance is usually slightly worse.
Every job on the system is assigned a priority, a number that tells the operating system how much priority to give the job when it doles out resources (the higher the number, the lower the priority). Commands that you enter from the shell, whether foreground or background jobs, usually have the same priority. The system administrator is able to run commands at a higher priority than normal users.
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
Note that if you're on a multiuser system, running lots of background jobs may eat up more than your fair share of resources, and you should consider whether having your job run as fast as possible is really more important than being a good citizen.
Speaking of good citizenship, there is also a UNIX command that lets you lower the priority of any job: the aptly named nice. If you type nice command, where command can be a complex shell command line with pipes, redirectors, etc., then the command will run at a lower priority.[16] You can control just how much lower by giving nice a numerical argument; consult the nice manpage for details.[17]
[14] Compressed files are created by the compress utility, which packs files into smaller amounts of space; they have names of the form filename.Z, where filename is the name of the original uncompressed file.
[15] You could use diff warandpeace* as a shorthand to save typing—as long as there are no other files with names of that form. Remember that diff doesn't see the arguments until after the shell has expanded the wildcards. Many people overlook this use of wildcards.
[16] Complex commands following nice should be quoted.
[17] If you are a system administrator logged in as root, then you can also use nice to raise a job's priority.