17. System Control
Introduction to FreeBSD
17.1.  Process Control
17.2.  Accessing The Floppy Drive

17.1.   Process Control

Whenever you execute a command at the UNIX prompt, FreeBSD assigns it a Process IDentification number or PID. This is a number between 1 and 65535. This number will be used to identify and control the process the entire time that it is running. When the program terminates, the Number will be recycled into the stack and reassigned when the kernel has cycled completely though all 65535 numbers.

If the same program is run again, it will be given a different PID and FreeBSD will track it through this new number. If two copies of the same program are started at the same time, two individual PID numbers will be assigned; one to each.

ps will give you a listing of all the process you have running.

>ps

PID TT STAT TIME COMMAND

12346 p0 Is+ 0:00.57 -tcsh (tcsh)

9871 p0 R+ 0:00.57 ps 

ps -a will give you a listing of all of the process running on the system.

To stop a process, you can use the kill command. Select the PID of the process you want to stop. Then type

kill -KILL PID.

For Example to kill process #12346 you would type:

>kill -KILL 12346

Process # -1 refers to every running process that you own. If you have several process running, you can kill all of them, (except your current shell) by typing:

kill -HUP -1

As root, you can use this command to kill, or restart, every process in the system.

If you don't want to use the PID, you can use the program killall. killall requires that you specify the name of the program running as a command line argument. Then it kills every instance of that program that it finds, providing you have permission to kill that program.

For instance:

killall make

would kill all make processes that you have running.

In addition to a priority, each process is assigned a ``Niceness'' value. The default value is 0. The users can give a nice value of up to +20, making processes run slower; freeing up processor time for more important processes. The ``nicer'' a program is, the more it allows other programs to run. Root can give values down to -20, making important processes run faster. All child processes, processes started by a program, inherit the nice value from the parent program. If you give a nice value of -20 to a make world all processes spawned by that program will have the nice value of -20. ie. all compiler processes generated will run at a nice of -20.

To give a program a nice value, precede your command with nice. If you wanted to start ppp with a nice value of +10 you would use:

> nice +10 ppp

If you want to change the nice value of a process that is already running, you would use renice followed by the process ID. To change the niceness value of process #1234 from the default of Zero to -10, you would use:

> renice -10 1234

'Nicing' or 'renicing' to +10 is the most common use of the (re)nice command. It's really just a way of telling FreeBSD that you aren't too concerned about the process finishing immediately, and it's okay to let other processes use more CPU time than your process. Usually, if you are going to run a program that you know will take a long time to run (say 5 minutes or greater) it is considered 'polite' to nice +10 the program. You're program will still finish very quickly. In fact, if the system isn't very busy there will be almost no difference, since no other processes are battling for the CPU!. Unless the system is very overloaded, a nice value of +10 will NOT result in a slow down. When you raise the niceness value of a running program, your program isn't put on hold until others are done, it just receives a smaller percentage of the CPU time. A nice value of +20 indicates that the application in question should ONLY run when the CPU is completely free. Generally, the only time a process is run with a nice value of +20 is when you don't want it to slow down any other aspect of the system.

top is pa process monitoring tool that helps you keep track of system resources. It displays the Active Processes, CPU Utilization, Swap Space Usage, and Memory Available. It also allows you to renice and kill processes. If you watch the CPU utilization, you will notice that it sits at about 90% IDLE most of the time. (Active Servers won't have so many Free Cycles.) Many system administrators find ways to utilize these idle CPU Cycles with creative applications of nice, renice, and top. Processor intensive, time consuming processes can be set to run in the background and only use up IDLE CPU Cycles, allowing your program to run and not infringe on regular operations.

17.2.   Accessing The Floppy Drive

FreeBSD looks at file systems in ``slices'' or partitions. Each file system is assigned to a device. The Floppy Drive is assigned the device ``fd''. The devices are also numbered, starting with 0. The first floppy disk is fd0. Filesystem devices are further divided up into slices. Each slice is assigned a letter. The letter is appended to the device name and number. Traditionally, slices a through h are available. Some slices have special meanings:

a ) This refers to the boot sector of the disk only.

b ) This refers to the swap space on the disk if there is any.

c ) This references the Whole Disk. Usually what you want.

e-h ) This and other such letters would refer to non-bootsector
slices if the disk happened to be divided up further.

Access to devices is granted through file representations of those devices contained in the /dev/ directory. Each slice has its own file representation. Therefore to access the whole floppy disk you would reference the file: /dev/fd0c. To actually get at the contents of the disk, you have to mount it into the file system under a directory. If you have a FreeBSD formatted Floppy disk, you can just use the mount command without any special parameters. You will have to specify a directory that exists on the system that you have write permission to, and have permission to access the device file you are trying to mount. By default, general users don't have access to the floppy disk device files.

To mount the floppy to a directory called /mnt you would type:

mount /dev/fd0c /mnt

Then cd to /mnt and work with the files that are there.

If you have a MSDOS disk that you want access to, you will use the command:

mount_msdos /dev/fd0c /mnt

To check and see if it mounted you can cd to the directory and do an ls, or type df and df will give you a list of all the file systems that are currently mounted and where they are mounted to. It will also show all the amount of space used.

Mounting a MSDOS floppy would give you access to the floppy just like a regular directory on the system, however it will automatically truncate the file names of any files copied to that directory to the dos 8.3 notation. (ie. FreeBSD.File.long.name will become FreeBSD.Fil)

When you are done with the floppy disk, you will have to unmount it from the file system. To do this type:

umount /dev/fd0c

OR

umount /mnt

Either one will successfully unmount the file system. You cannot unmount a file system while you are in the directory that the filesystem is mounted to. This will give you a device busy error. You will have to cd out of that directory before unmounting it.

Now when you cd to /mnt it should be empty.

Return to Table of Contents

Visit the Gifcom