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.cgcc -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启动helloservice test start2.6 设置开机自动启动chkconfig --add test chkconfig test on/off //重启后永久生效
查看原文:http://newmiracle.cn/?p=2373
linux写系统服务的方法
最新推荐文章于 2024-07-13 14:28:23 发布