A Systems Lab User Guide
Beyond the Handouts
There are several resources available already with basic information about how to use the various resources available in the TJHSST Computer Systems Lab. Mr. Hyatt's page is an excellent place to start. However, in the two years I've spent there (well, not all of those two years, but pretty close), I've found or been shown several helpful programs and other things. I haven't found any reference that has all of these, so I decided to assume none exist and make my own.
Man and Info
First, what are most likely the two most useful tools on Linux - man and info. Man is the standard Unix help utility. Type man followed by nearly any command, and it will give you help on this command. (And yes, you can type man man if you really want to.)
- One useful thing to know about this is that it is divided into eight sections, numbered 1-9. You can get a list of what each section is by using
man man. The most useful ones to know are 1, which is the standard "user commands" that you obtain from the shell, and 3 is library calls (many C commands are here). - As implied above, many C commands have their own manpages! For example, try typing
man printf. Wait... that's not a C command! That's a program you run from the command line! But this is where knowing the section numbers is useful... Tryman 3 printf. This gives you the C version. This could be very useful if you forget something about it. Many other commands found in include files are in the manpages... (sleep, usleep, getc, scanf, and others). - And man pages aren't limited to just C! Try man perl - it gives you a list of various perl man pages. And I'm sure there are other interesting pages I haven't found.
- But there's more than just man... there's also
info. For programs that have info pages, they're generally much more complete than the man pages. For example,man pythongives a concise listing of all the command line arguments you can pass to the python interpreter. Butinfo pythongives a full introduction to the Python language. However, while the manpages are typically displayed inlessor a similar program, info pages are generally displayed in a more Emacs-ian (yes, I know it's probably not a word) editor. Type 'h' the first time you run it to learn how to use it.
Processes Listings
Whenever you run a program on Linux (or on Windows and, most likely, just about every multi-tasking operating system in existence), a new process is start for this program. But that knowledge doesn't do very much; you also have to know how to monitor and stop them. Linux provides several useful utilities for this.
- ps - this is the basic process monitoring tool. When run, it gives a list of all the processes you've run from that shell. Not all that helpful. However, when you add options (the most common three are
- top - this is like
ps, except it is "interactive". It shows information about processes in (almost) real time. The most useful commands to know here are 'h', which gives you help (always nice to have), 'u', which lets you show only a single user's processes, and 's', which let's you change the time between updates (don't make it too fast, or else top takes up lots of CPU time.).
a, u, and x), you can get more useful information. If you use a, you get all user's processes (not just your own), u adds the username of the owner to the information you get about each process, and x gives processes "without controlling ttys" according to the man page; basically, it gives all of you processes. Another useful option is f: this option will display processes in a flow chart, showing where each process came from. A similar command is pstree which seems to require that you pass a username after it.
Process Control
In addition to monitoring processes, you can start and stop them. Starting them is generally simple: run a program (though it can be more complex if you really want). However, you can do all sorts of fun things with them once they're started.
- The all powerful
&: this lets a program run in the background. Normally when you start a program, you can't do anything else with the shell until the program terminates. However, the&will let the program continue running without hogging the terminal. However, this doesn't suppress output: if it prints to the screen, it will still print, possible in the middle of something else. And if you close the terminal, the process will still be killed. So this doesn't work if you want a program to keep running after you log out. There are ways to do that, however... keep reading to find out. - Of course you know about ^C (a.k.a. Control-C). This will (usually) stop a program and terminate it. However, what if you don't want to stop it, you just want to have the terminal back for a second? That's where ^Z (Control-Z, for those of you who haven't seen that pattern yet) comes in. It simply stops the program without killing it, and gives you a display something like
[1]+ Stopped vim. This tells you that it's "job" number 1, that it's stopped, and that it was run with the command "vim". So now (or anytime actually, but it's usually pretty boring), you can typejobswhich will give you a list of all processes that you have stopped or running in the background. You can typefgto put the most recent job (the one with the '+' next to it) in the foregground, orbgto put it in the background. Or, if you want a different process, you can do something likefg %2, where 2 is the number you got from runningjobs. - You can use
ulimitto set limits on things like memory size, cpu time, and max user processes. Typeulimit -ato see what all the current limits are. And you can also see the options you passulimitto change them. For example,ulimit -t 120would mean that no program can use more than 2 minutes (120 seconds) of cpu time before it will be automatically killed. Note, however, that once you set a limit, you cannot increase it unless you are root, which you most likely are not. But if you open up a new console/xterm, the limits will be reset to the system default. - But the default cpu time limit is only two hours (at the moment I'm writing this). What if you want a simulation to run for more than that? You can't increase the limit, right? But it turns out that the cpu time limit is a soft limit. So you can increase it yourself! Try it:
ulimit -t unlimited. You can now run a program as long as you want. How do you set a soft limit? Just prefix S before the option:ulimit -St 60. Now no process can run for more than 60 seconds, but you can increase it later if you want.