Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman (best business books of all time txt) đź“–
- Author: John Goerzen and Ossama Othman
- Performer: -
Book online «Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman (best business books of all time txt) 📖». Author John Goerzen and Ossama Othman
is the current directory, and .. is the parent of the current directory; because these are guaranteed to be in every directory, there is no real reason to list them with ls. You already know they are there.
Processes
We mentioned before that GNU/Linux is a multitasking system. It can do many tasks at once. Each of these tasks is called a process. The best way to get a sense of this is to type top at the shell prompt. You’ll get a list of processes, sorted according to how much of the computer’s processing time they’re using. The order will continuously change before your eyes. At the top of the display, there’s some information about the system: how many users are logged in, how many total processes there are, how much memory you have and how much you’re using.
In the far left column, you’ll see the user owning each process. The far right column shows which command invoked the process. You’ll probably notice that top itself, invoked by you, is near the top of the list (because anytime top checks on CPU usage, it will be active and using CPU
to do the check).
Note that in all the commands ending in “d” - such as kflushd and inetd - the “d” stands for daemon.
Daemon originally meant Disks And Extensions MONitor. A daemon is a non-interactive process, that is, it’s run by the system and users never have to worry about it. Daemons provide services like Internet connectivity, printing, or e-mail.
Now press u and give top your username when it asks. The u command asks to see only those processes belonging to you; it allows you to ignore all the daemons and whatever other people are doing. You might notice bash, the name of your shell. You’ll pretty much always be running bash.
Note that column two of the top display shows you the PID, or Process IDentification number. Each process is assigned a unique PID. You can use the PID to control individual processes (more on that later). Another useful trick is to press ? to get a list of top commands.
You may wonder about the difference between a “process” and a “program.” In practice, people use the terms interchangeably.
Technically, the program is the set of instructions written by a programmer and kept on disk. The process is the working instantiation of the program kept in memory by Linux. But it’s not that important to keep the terms straight.
Much of your interaction with a computer involves controlling processes.
You’ll want to start them, stop them, and see what they’re up to. Your primary tool for this is the shell.
The Shell
The shell is a program that allows you to interact with your computer.
It’s called a shell because it provides an environment for you to work in - sort of a little electronic home for you as you compute. (Think hermit crab.)
The simplest function of the shell is to launch other programs. You type the name of the program you want to run, followed by the arguments you want, and the shell asks the system to run the program for you.
Of course, graphical windowing systems also fill this need. Technically, Windows 95 provides a graphical shell, and the X Window system is another kind of graphical shell. But “shell” is commonly used to mean “command-line shell.”
Needless to say, the hackers who work on shells aren’t satisfied with simply launching commands. Your shell has a bewildering number of convenient and powerful features if you would like to take advantage of them.
There are countless different shells available; most are based on either the Bourne shell or the C shell, two of the oldest shells. The original Bourne shell’s program name is sh, while csh is the C shell. Bourne shell variants include the Bourne Again Shell from the GNU project (bash, the Debian default), the Korn shell (ksh), and the Z shell (zsh). There is also ash, a traditional implementation of the Bourne shell. The most common C shell variant is tcsh (the t pays tribute to the TENEX and TOPS-20 operating systems, which inspired some of tcsh’s improvements over csh).
bash is probably the best choice for new users. It is the default and has all the features you’re likely to need. But all the shells have loyal followings; if you want to experiment, install some different shell packages and change your shell with the chsh command. Just type chsh, supply a password when asked, and choose a shell. When you next log in, you’ll be using the new shell.
Managing Processes with bash Debian is a multitasking system, so you need a way to do more than one thing at once. Graphical environments like X provide a natural way to do this; they allow multiple windows on the screen at any one time.
Naturally, bash (or any other shell) provides similar facilities.
Earlier you used top to look at the different processes on the system.
Your shell provides some convenient ways to keep track of only those processes you’ve started from the command line. Each command line starts a job (also called a process group) to be carried out by the shell. A job can consist of a single process or a set of processes in a pipeline (more on pipelines later).
Entering a command line will start a job. Try typing man cp, and the cp manual page will appear on the screen. The shell will go into the background and return when you finish reading the manual page (or you can press q to quit rather than scrolling through the whole thing).
But say you’re reading the manual page, and you want to do something else for a minute. No problem. Press Ctrl-z while you’re reading to suspend the current foreground job and put the shell in the foreground. When you suspend a job, bash will first give you some information on it, followed by a shell prompt. You will see something like this on the screen: NAME cp - copy files SYNOPSIS cp [options] source -More-
[1]+ Stopped man cp
$
Note the last two lines. The next to last is the job information, and then you have a shell prompt.
bash assigns a job number to each command line you run from the shell.
This allows you to refer to the process easily. In this case, man cp is job number 1, displayed as [1]. The + means that this is the last job you had in the foreground. bash also tells you the current state of the job -
Stopped - and the job’s command line.
There are many things you can do with jobs. With man cp still suspended, try the following commands:
man ls
Starts a new job.
Ctrl-z
Suspends the man ls job; you should see its job information.
man mv
Starts yet another job.
Ctrl-z
Suspends it.
jobs
Asks bash for a display of current jobs. The result looks like this: {$} jobs
[1] Stopped man cp
[2]- Stopped man ls
[3]+ Stopped man mv
{$}
Notice the - and +, denoting respectively the next to last and last foreground jobs.
fg
Places the last foreground job (man mv, the one with the +) in the foreground again. If you press the space bar, the man page will continue scrolling.
Ctrl-z
Re-suspends man mv.
fg %1
You can refer to any job by placing a % in front of its number. If you use fg without specifying a job, the last active one is assumed.
Ctrl-z
Re-suspends man cp.
kill %1
Kills off job 1. bash will report the job information, which will look like this:
$ kill %1
[1]- Terminated man cp
$
bash is only asking the job to quit, and sometimes a job will not want to do so. If the job doesn’t terminate, you can add the -KILL5.1 option to kill to stop asking and start demanding. For example: $ kill -KILL %1
[1]- Killed man mv
$
The -KILL option forcibly and unconditionally kills off the job.
In technical terms, kill simply sends a signal. By default, it sends a signal that requests termination (TERM, or signal 15) but you can also specify a signal, and signal 9 (KILL) is the signal that forces termination. The command name kill is not necessarily appropriate to the signal sent; for example, sending the TSTP (terminal stop) signal suspends the process but allows it to be continued later.
top
This brings the top display back up. Give the u command in top to see only your processes. Look in the right-hand column for the man ls and man mv commands. man cp won’t be there because you killed it. top is showing you the system processes corresponding to your jobs; notice that the PID on the left of the screen does not correspond to the job number.
You may not be able to find your processes because they’re off the bottom of the screen; if you’re using X (see Chapter 9 on page [*]), you can resize the xterm to solve this problem.
Even these simple jobs actually consist of multiple processes, including the man process and the pager more, which handles scrolling one page at a time. You may notice the more processes are also visible in top.
You can probably figure out how to clean up the remaining two jobs. You can either kill them (with the kill command) or foreground each one (with fg) and exit it. Remember that the jobs command gives you a list of existing jobs and their status.
One final note: The documentation for bash is quite good, but it is found in the Info help system rather than the man pages. To read it, type info bash. See section A.1.1 for instructions on using the info program. bash also contains a very good summary of its commands accessible by the help command. help displays a list of available topics; more information about each of them is accessible with the command help topic name. Try typing help cd, for example. This will give you details on the -P and -L
arguments recognized by cd.
A Few bash Features This section mentions just a few of the most commonly used Bash features; for a more complete discussion see Chapter 6.
Tab Completion
The bash shell can guess what filename or command you are trying to type and automatically finish typing it for you. Just type the beginning of a command or filename and press Tab. If bash finds a single unique completion, it will finish the word and put a space after it. If it finds multiple possible completions, it will fill out the part all completions have in common and beep. You can then enter enough of the word to make it unique and press Tab again. If it finds no completions, it will simply beep.
Managing Your Identity Unix-like systems are multiuser, and so you have your own electronic identity as a user on the system. Type finger yourusername to look at some of the information about you that’s publically available. To change the name and shell listed there, you can use the commands chfn and chsh. Only the superuser can change your login (username) and directory. You’ll notice that it says “No plan.” A “plan” is just some information you can make available to others. To create a plan, you put whatever
Comments (0)