Cover V02, I03
Article
Listing 1
Listing 2
Sidebar 1

may93.tar


Sidebar: How rc Scripts Work

All rc scripts should reside in the directory /etc/init.d. The scripts should then be linked to a file in /etc/rc2.d or /etc/rc3.d, and /etc/rc0.d. These directories correspond with the run levels 2, 3, and 0. init() will read inittab and execute the scripts associated with the run level it is about to enter. When executing the rc scripts, init passes along an argument to the script. The argument will either be "start" or "stop." Therefore, the same script should be written for starting and stopping a process.

Scripts are executed in alphanumeric order. Scripts to be executed while the system is coming up will usually be linked to files in /etc/rc2.d and will begin with the letter S (for "Start") followed by a number and a name related to the operation, such as inet, cron, or lp. Lower numbers will be executed first. Scripts to be executed while the system is going down should be linked to files in /etc/rc0.d and begin with a K (for "Kill"), followed by a number and a name. Once again, lower numbers will be executed first. S files and K files may be in the same rc directories. The S files are run when init starts the run level; the K files in the same directory are run just before init kills that run level. init then moves on to the next run level, which has its own S and K files. This is how the system controls the order of events upon boot and shutdown.