linux寫系統服務的方法 2.1 首先編寫demo程序:hello.c
#include main() { FILE *fp; char a[] = "Hello world!"; fp=fopen("hhh.txt","a+"); fputs(a,fp); return 0; }2.2 編譯hello.c
gcc -g hello.c -o hello2.3 在/etc/init.d目錄下添加腳本test
#!/bin/bash start(){ echo "------------------test----------------" cd /home/xxx //hello的所在文件夾的絕對路徑 ./hello } case $1 in start): start ;; stop): echo "-----------------stop------------------" ;; esac exit 02.4 設置權限
chmod 777 /etc/init.d/test2.5 利用service啓動hello
service test start2.6 設置開機自動啓動
chkconfig --add test chkconfig test on/off //重啓後永久生效
查看原文:http://newmiracle.cn/?p=2373