UNIX User's Guide > Advanced UNIX Commands
- Monitoring Your Disk Usage: quota
- Input/Output Redirection and Pipes
- Managing Processes: ps and kill
- Job Control
Monitoring Your Disk Usage: quota
Each user on the system is allotted a certain amount of disk space for his or her files. You can see how much space you are using with the command quota -v. If you are near your quota, you should delete files you no longer need.
In the following example, we see that "Godzilla" has 64 files, which take up 2315 blocks. Each block is 1024 bytes of disk space (which means that he is using about 2.3 megabytes). He has been allotted 5000 blocks, but is permitted to temporarily exceed that by 500 blocks.
Nova> quota -v
Disk quotas for godzilla (uid 2093):
Filesystem usage quota limit timeleft files quota limit timeleft
/class 0 1 1 0 0 0
/users 2315 5000 5500 64 0 0
Input/Output Redirection and Pipes
Most programs you run take input from standard input (stdin) and send output to standard output (stdout). By default, these are (respectively) the terminal keyboard and the terminal display. However, it is possible to redirect input and output to disk files as well as to other programs.
The right angle bracket symbol (>) is used to redirect output to a disk file. If the file specified does not already exist, it is created; if it does exist, it is overwritten. The left angle bracket symbol (<) is used to redirect input from a disk file. To append output to an existing file, use double right angle brackets (>>).
Nova> who > who.output
Nova> cat who.output
rodan pts/10 Jul 19 09:13 (sgannex.umuc.edu)
gamera pts/5 Jul 19 14:04 (caeannex1.umuc.edu)
godzilla pts/14 Jul 19 10:24 (caves.tokyo.com)
Nova> sort < who.output
gamera pts/5 Jul 19 14:04 (caeannex1.umuc.edu)
godzilla pts/14 Jul 19 10:24 (caves.tokyo.com)
rodan pts/10 Jul 19 09:13 (sgannex.umuc.edu)
A pipe, indicated by the vertical bar symbol (|), takes the output from the command to its left and uses it as the input to the command to its right. The final output in the preceding example can be achieved with the following use of a pipe:
Nova> who | sort
gamera pts/5 Jul 19 14:04 (caeannex1.umuc.edu)
godzilla pts/14 Jul 19 10:24 (caves.tokyo.com)
rodan pts/10 Jul 19 09:13 (sgannex.umuc.edu)
Managing Processes: ps and kill
Every command or program you execute creates a process on the system. Each process is assigned a unique process ID (PID) by the system. You can use the ps command to display the processes running under your session.
Nova> ps
PID TTY TIME COMD
21727 pts/5 0:03 -tcsh
22102 pts/5 0:00 ps
The fields are the process ID, the associated terminal, number of CPU seconds used by the process, and the name of the command used to start the process.
In the preceding example, the two processes shown are the login shell (tcsh) and the ps command itself. A more informative listing can be displayed with the -f and -u options. The -f option provides a full listing, and the -u option lets you specify a user ("Godzilla" in the following example). All processes owned by the specified user are displayed. Please note that this list may include more processes than those associated with the current session.
In the following example, there is a File Transfer Protocol (FTP) process listed with a question mark (?) in the TTY column. This means there is no longer a terminal associated with that process. This sometimes happens when your connection to the UNIX system is abruptly terminated. If you do get unexpectedly dropped from the system, you should log back on and use ps -fu and kill to remove leftover processes.
Nova> ps -fu godzilla
UID PID PPID C STIME TTY TIME COMD
godzilla 21727 21723 56 14:04:42 pts/5 0:03 -tcsh
godzilla 19354 1 20 13:02:32 ? 0:05 ftp
godzilla 22102 21727 16 14:12:23 pts/5 0:00 ps -fu godzilla
Nova> kill 19354
Nova> ps -fu godzilla
UID PID PPID C STIME TTY TIME COMD
godzilla 21727 21723 56 14:04:42 pts/5 0:03 -tcsh
godzilla 22115 21727 16 14:12:47 pts/5 0:00 ps -fu godzilla
Job Control
The UNIX operating system gives you the ability to run several processes at once. UNIX also lets you switch between these processes, bringing one to the foreground while the others remain running in the background. A job is just a collection of processes; a single process is also considered a job.
The shell allows you to run jobs in the foreground, in the background, or suspended. A foreground job is one you are using interactively. A background job is one that is executing in the background, not directly interacting with you. A suspended job is paused, waiting for you to restart it (either in the foreground or background) or to terminate it.
You can run a command in the background by following the command with an ampersand (&). Use the jobs command to see which jobs are running under your current session. The number at the left is the job number, which you can use with the fg and bg commands (discussed in the following paragraph). The current job is indicated with a plus sign (+); this job will be the default target for any job control commands you use without specifying a job number.
Nova> sort mydata > mydata.sorted &
Nova> jobs
[1] + 9995 Running sort mydata > mydata.sorted
The fg command can be used to bring a job to the foreground. Executing the command with no parameters brings the current job to the foreground. To specify a particular job, type %1 for job 1, %2 for job 2, and so on. A suspended process may be placed in the background with the bg command. As with the fg command, if a job number is not specified, the default is the current job. The bg command is most often used after a foreground process has been suspended with [CTRL]Z.
Nova> ftp caves.tokyo.org ftp> get hugefile.txt 150 Opening ASCII mode data connection... [CTRL]Z Suspended Nova> jobs [1] - 9995 Running sort mydata > mydata.sorted [2] + 9998 Suspended ftp caves.tokyo.org Nova> bg [2] ftp caves.tokyo.org & Nova> jobs [1] - 9995 Running sort mydata > mydata.sorted [2] + 9998 Running ftp caves.tokyo.org {Do something else while FTP continues running in the background..} Nova> fg %2 ftp caves.tokyo.org 226 Transfer complete. ftp> quit Nova>
Computing Resources Home