Updated: 2012-04-13 05:55 EDT

1 Tests and Exams Index up to index

2 Lecture Notes for This Week Index up to index

2.2 From the Classroom Whiteboard/Chalkboard Index up to index

How Many Lines 

2.3 Choosing a File System Type Index up to index

Your system install created “journalling” file systems on your virtual disk, using the “-t ext3” option to mkfs. Another way to request this kind of file system is to use the “-j” (Journalling) option to the original “mke2fs” command. This type of Linux journalling file system is usually called “ext3”, and some distributions have a small shell script named “mke3fs” that simply calls mke2fs with the “-t ext3” or “-j” option.

Journalling file systems are more resistant to corruption due to sudden power loss, allowing the system to come back up more quickly by avoiding a long file system check at boot time. (This does NOT give you permission to power off a running Linux system! Always shut down cleanly.)

2.4 System Logging - syslog and /var/log/ Index up to index

Logging of system messages is handled by a syslog process, a process that listens for connections and writes messages to log files.

System logging is configured via files in /etc such as /etc/syslog.conf, /etc/rsyslog.conf, etc. The syslog process is started by system start-up scripts such as klogd, sysklogd, rsyslogd, etc. The main daemon name is usually something like “syslogd” or “rsyslogd” or “klogd”.

$ ps laxww | grep syslog
$ ps laxww | grep klogd

Logs are usually stored under directory /var/log/; but, the configuration file may have syslog put them anywhere.

2.5 Unix/Linux Shell Job Control and Background Processes Index up to index

Normally when you run a command, the shell waits until the command is finished before it prompts you for the next command. If you want to run a command “in the background”, without waiting for it to finish, and have the shell prompt you immediately, end the command with an ampersand &, e.g.

$ sleep 60 &
[1] 18920

If you have already typed a command and forgot to use the &, you can put a foreground process into the background by typing ^Z (CTRL-Z) to suspend the process, followed by bg to put it into the background:

$ sleep 60
[1]+  Stopped                 sleep 60
$ bg
[1]+ sleep 60 &

You can bring a background job into the foreground using fg:

$ jobs
[1]+  Running                 sleep 60 
$ fg
sleep 60

You can list the jobs of the current shell using the jobs command.

$ jobs
[1]+  Running                 sleep 60 

You can send signals, including termination signals, to jobs of the current shell:

$ kill %1
[1]+  Terminated              sleep 60

2.6 Process listing and control Index up to index

Programs runs as individual processes. Each process has a numeric process ID or PID. A process usually runs with the userid and group permissions of the person who started it. Some privileged setuid programs can run with the userid and/or group of the file containing the program.

You can usually see the process IDs of all user processes, but you can only terminate or pause your own processes.

The “ps” command on Linux is a mix of the BSD “ps” command and the incompatible SystemV UNIX “ps” command. From “man ps”:

This version of ps accepts several kinds of options:
  1   UNIX options, which may be grouped and must be preceded by a dash.
  2   BSD options, which may be grouped and must not be used with a dash.
  3   GNU long options, which are preceded by two dashes.

 $ ps        # BSD: some of your processes (in current window)
 $ ps x      # BSD: all of your processes 
 $ ps xl     # BSD: all your processes, long format
 $ ps xlww   # BSD: all your processes, long format, full wide listing
 $ ps ax     # BSD: all processes
 $ ps laxww  # BSD: all processes, long format, full wide listing
 $ ps f      # BSD: ascii art hierarchical display (forest)
 $ ps -e     # UNIX: all processes
 $ ps -elww  # UNIX: all processes, long format, full wide listing
 $ pstree    # process tree; similar to "ps axf"
 $ kill      # send (TERMinate) signal to a process ID or job number
 $ killall   # send (TERMinate) signal to a process with a given name
 $ jobs      # show child processes of current shell

2.7 Scheduled Execution - cron and crontab Index up to index

Unix/Linux has a program named cron that runs other programs at scheduled times, e.g. run a backup program every day at midnight. The cron daemon examines and runs crontab entries once every minute. (The cron daemon can’t run anything more often than once a minute.)

There is a system cron configuration file /etc/crontab that can run commands as any userid (usually as root). Most systems also allow individual users to have private crontab files for commands they want to run as themselves. You simply use an editor to edit the system /etc/crontab file. Users must use the crontab command to manage their personal cron files.

# example line from a personal crontab file:
34 12 * * * echo "It's 12:34 and time to eat lunch" | write alleni

The five time and date fields at the start of crontab lines are (from man 5 crontab):

crontab field allowed values
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

2.8 Pre-scripting Shell Topics Index up to index

| Ian! D. Allen  -  idallen@idallen.ca  -  Ottawa, Ontario, Canada
| Home Page: http://idallen.com/   Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom:  http://eff.org/  and have fun:  http://fools.ca/

Plain Text - plain text version of this page in Pandoc Markdown format

Campaign for non-browser-specific HTML   Valid XHTML 1.0 Transitional   Valid CSS!   Creative Commons by nc sa 3.0   Hacker Ideals Emblem   Author Ian! D. Allen