综合资讯 技术文章 原文阅读 在线商城 下载专区 DATASHEET 技术论坛 商务频道

电子技术 | 技术资料 | 嵌入式系统 | 单片机专题 | DSP专题
EDA/PLD专题 | 电源技术专题 | 电子制作专题 | 其他综合 | 芯片选型

所在的位置:首页在线阅读嵌入式系统linux 笔记(一)正文
 
系统管理—启动—/etc/rc?.d目录和/etc/rc?文件

/etc/rc?.d目录和/etc/rc?文件

发信人: cloudsky (晓舟·轩辕明月), 信区: Linux
标  题: /etc/rc?.d目录和/etc/rc?文件简介
发信站: 武汉白云黄鹤站 (Thu Feb  4 22:31:41 1999) , 转信

标题:/etc/rc?.d目录和/etc/rc?文件分析

    运行级0-6分别对应着一个/etc/rc?.d目录和一个/etc/rc?文件。rc?文件是个shell script,从/etc/inittab文件分析中可以看到,当进入运行级?时,rc?文件就会得到执行。从上面的示例文件中看到缺省实际运行级是3,注意到rc2也被执行了,下面是rc2示例

#!/sbin/sh
PATH=/usr/sbin:/usr/bin
set `/usr/bin/who -r`
if [ x$9 = "xS" -o x$9 = "x1" ]
then
        echo 'The system is coming up.  Please wait.'
        BOOT=yes
elif [ x$7 = "x2" ]
then
        echo 'Changing to state 2.'
        if [ -d /etc/rc2.d ]
        then
                for f in /etc/rc2.d/K*
                {
                        if [ -s ${f} ]
                        then
                                case ${f} in
                                        *.sh)   .        ${f} ;;
                                        *)      /sbin/sh ${f} stop ;;
                                esac
                        fi
                }
        fi
fi
if [ x$9 != "x2" -a x$9 != "x3" -a -d /etc/rc2.d ]
then
        for f in /etc/rc2.d/S*
        {
                if [ -s ${f} ]
                then
                        case ${f} in
                                *.sh)   .        ${f} ;;        # source it
                                *)      /sbin/sh ${f} start ;;  # sub shell
                        esac
                fi
        }
fi
#if [ ! -s /etc/rc2.d/.ports.sem ]
#then
#       /sbin/ports
#       echo "ports completed" > /etc/rc2.d/.ports.sem
#fi
# Start historical section.
if [ "${BOOT}" = "yes" -a -d /etc/rc.d ]
then
        for f in `/usr/bin/ls /etc/rc.d`
        {
                if [ ! -s /etc/init.d/${f} ]
                then
                        /sbin/sh /etc/rc.d/${f}
                fi
        }
fi
# End historical section.
if [ "${BOOT}" = "yes" -a x$7 = "x2" ]
then
        echo 'The system is ready.'
elif [ x$7 = "x2" ]
then
        echo 'Change to state 2 has been completed.'
fi

    可以看到,rc2的主要任务是启动或终止/etc/rc2.d目录下的相关文件,这些文件也是shell script文件。这些文件具有如下格式:S??name或者K??nameK表示当进入运行级2时需执行此文件以终止某些进程,S表示当进入运行级2时需执行此文件以启动某些进程。??是00-99的数字,代表了终止和启动的顺序。name对应一个文件名,通常是/etc/init.d/name,注意这实际是些硬链接。


返回 上一页 下一页   信息发布:工号01   转引自: 【 】 【打印】 【关闭

关于我们 ┋ 友情链接


深圳市福田区海滨广场恒福花园恒华阁11F
电话:0755-88305872 传真:0755-88305880
Copyright©2005-2007 无忧电子开发网版权所有

粤ICP备05064233号