Comp 2673, Spring 2002
April 24, lecture notes
Reading: Read Chapter 17 in the Unix book (the subject is job control) Finish reading D&D, 9.1-9.6, 9.8 Job control in Unix - Recall that Unix is a multi-user, multi-tasking operating system. You, as a user, can run several jobs at once. There are several commands for helping you keep track of what you've got running. - Here are some important commands and keyboard controls to know for managing jobs and processes: Ctrl-c, Ctrl-z, % command &, bg, fg, kill, ps, nice, renice - Foreground and background: If you type a command to the shell, that command runs in the "foreground". Commands can be run in the "background" as well, by appending a '&' onto the end of your command. % family_tree widefamily & starts your program family_tree with the argument widefamily and runs it in the background. This allows you to continue interacting with the shell while your program is running. Even better: % family_tree widefamily > widefamilyout & The output to the terminal is redirected to a file. When/if the program reaches a point that it needs input, that job will stop temporarily and wait for you to move it into the foreground. - Suspending jobs, moving a job from foreground to background: While you're running a job, you might choose to suspend a job temporarily to go do something else. Hit Ctrl-Z, and that suspends the job. (Don't get this mixed up with Ctrl-C, which kills the job that's running.) When you want to return to the job, you type % fg which restarts (continues) the job in the foreground, or % bg which restarts (continues) the job in the background. - Getting a list of all the jobs running: Type % jobs It'll give you a list of jobs. + means the current job, - means the previous job. Each job also has a number, and you can refer to a job by its number, %1 being job 1, %2 being job 2, etc. There are several Unix commands that use these job numbers, for example % fg %2 % bg %2 % kill %1 - Sometimes you have to kill a process that you don't know the job number for, or is associated with some other shell. You can kill it if you know its process id. Use ps to find its process id. % ps -a gives a list of all processes, including their process ids. % kill 12345 kills the process with process id 12345 (provided you own it!) - If you are running a program that takes a lot of time and a lot of cpu, then run it using the command "nice". This reduces its priority and interferes less with other users. For example: % nice myprogram myargument & - If you start a program and realize it's going to be a cpu pig and you didn't run it with nice, then you can "renice" it % renice 23425 reduces the priority of process 23425 (you use ps, of course, to find out the process's id).