zoukankan      html  css  js  c++  java
  • Fedora 16设置开机自启动程序与Ubuntu的区别

    Ubuntu设置开机自启动脚本的方法是:修改/etc/init.d/rc.local这个文件,添加需要启动的程序即可,相关函数如下:

    void SetSysAutoBoot()
    {
        char path[256] = {0};
        int ret = 0;
    
        ret = readlink("/proc/self/exe",path,sizeof(path));
    
        if((ret > 0 )&& (ret < sizeof(path)))
        {
            printf("system path  :  %s
    ",path);
        }
    
        char* fileName = "/etc/init.d/rc.local";
        int fileLen = GetFileSize(fileName);
    
        FILE * fp = fopen(fileName,"r+");
        char* buf;
    
        buf = (char*)malloc(fileLen*2);
        char* tempBuf = buf;
    
        if(fp == NULL)
        {
            return;
        }
    
        int flag = 0;
        
        while(!feof(fp))
        {
            tempBuf = fgets(buf,fileLen,fp);
    
            if(tempBuf != buf)
            {
                break;
            }
            
            //exist
            if(strstr(tempBuf,path) != 0)
            {
                //
                flag = 1;
            }
    
        }
    
        fclose(fp);
    
        //not exist
        if(0 == flag)
        {    
            char buf[1024];
            sprintf(buf,"echo "%s &" >> /etc/init.d/rc.local
    ",path);
            printf(buf);
            system(buf);
        }
        
        free(buf);
    }

    但是FC16系统并不系统自带/etc/init.d/rc.local这个文件,于是我们就要自作做一些配置了。

    1. 首先写一个测试脚本,

    touch /etc/rc.d/rc.local

    这个文件的内容是:

    #!/bin/sh
    date >> /IpMonitor/test.txt
    /IpMonitor/IpMonitor-Server &

    设置可执行权限:

    chmod 777 /etc/rc.d/rc.local

    设置软链接:

    ln -s /etc/rc.d/rc.local /etc/rc.local

    2. 开启rc-local.service

    systemctl start rc-local.service

    3. reboot即可看到效果了。

    top - 11:14:22 up 1 min,  2 users,  load average: 1.37, 0.57, 0.21
    Tasks: 160 total,   1 running, 159 sleeping,   0 stopped,   0 zombie
    Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.5%id,  0.1%wa,  0.2%hi,  0.1%si,  0.0%st
    Mem:   8152824k total,   442280k used,  7710544k free,      488k buffers
    Swap:  4095996k total,        0k used,  4095996k free,   137048k cached
    
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                   
      814 root      20   0  441m 2920  740 S  0.7  0.0   0:00.33 IpMonitor-Serve                                                                                           
        1 root      20   0 37384 4360 2008 S  0.0  0.1   0:01.32 systemd                                                                                                   
        2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                                                  
        3 root      20   0     0    0    0 S  0.0  0.0   0:00.01 ksoftirqd/0                                                                                               
        4 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/0:0                                                                                               
        5 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/u:0                                                                                               
        6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                                               
        7 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0                                                                                                
        8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1                                                                                               
        9 root      20   0     0    0    0 S  0.0  0.0   0:00.02 kworker/1:0                                                                                               
       10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/1                                                                                               
       11 root      20   0     0    0    0 S  0.0  0.0   0:00.02 kworker/0:1                                                                                               
       12 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/1                                                                                                
       13 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/2                                                                                               
       14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/2:0                                                                                               
       15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/2                                                                                               
       16 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/2                                                                                                
       17 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/3                                                                                               
       18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/3:0                                                                                               
       19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/3                                                                                               
       20 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/3                                                                                                
       21 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/4                                                                                               
       22 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/4:0                                                                                               
       23 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/4                                                                                               
       24 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/4                                                                                                
       25 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/5                                                                                               
       26 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/5:0                                                                                               
       27 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/5                                                                                               
       28 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/5                                                                                                
       29 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/6                                                                                               
       30 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/6:0                                                                                               
       31 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/6                                                                                               
       32 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/6                                                                                                
       33 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/7                                                                                               
       34 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/7:0                                                                                               
       35 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/7                                                                                               
       36 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/7                                                                                                
       37 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 cpuset                                                                                                    
       38 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                                                   
    [root@localhost ~]# 
    [root@localhost ~]# 
    [root@localhost ~]# cat /IpMonitor/test.txt 
    2013年 07月 05日 星期五 11:05:20 CST
    2013年 07月 05日 星期五 11:06:07 CST
    2013年 07月 05日 星期五 11:08:02 CST
    2013年 07月 05日 星期五 11:09:24 CST
    2013年 07月 05日 星期五 11:11:49 CST
    2013年 07月 05日 星期五 11:13:15 CST
  • 相关阅读:
    bzoj 1031: [JSOI2007]字符加密Cipher
    python re模块实现计算器
    python sys模块和序列化模块
    python time时间模块
    python 发红包的小程序
    python ranndom模块及生成验证码
    python os模块练习题
    python os模块常用命令
    快速排序,归并排序
    选择排序和插入排序
  • 原文地址:https://www.cnblogs.com/xiaowenhu/p/3173381.html
Copyright © 2011-2022 走看看