歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Fedora 16設置開機自啟動程序與Ubuntu的區別

Fedora 16設置開機自啟動程序與Ubuntu的區別

日期:2017/3/1 16:13:46   编辑:關於Linux
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\n",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\n",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 、
Copyright © Linux教程網 All Rights Reserved