Linux 学习第一篇
来源:互联网 发布:金庸群侠传x源码 编辑:程序博客网 时间:2024/06/05 20:05
其实小一志在不是做Linux 管理员,学习的原因先不说了,以免笑话。今天第一篇,发个Linux守护进程的。实在惭愧,没有什么技术含量。乱贴代码和截图。旨在千里之行,始于足下!
int fd , i; char *content ="yiran\n";
pid_t pid = fork(); //create process , exitparent
if(pid<0) exit(1); else if(pid>0) exit(0);
setsid();
for(i=0;i<10076; i++) close(i); //close all fd
chdir("/"); // change dir
umask(0); // initumask
while(1){ // dotask fd =open("/tmp/mylog.log",O_CREAT|O_RDWR|O_APPEND,06666); if(fd>0){ write(fd,content,strlen(content)); close(fd); } sleep(3); }
自创的一个守护进程,朋友们自己家尖括号吧:
#include stdio.h
#include unistd.h
#include stdlib.h
#include sys/types.h
#include sys/stat.h
#include fcntl.h
#include string.h
int main(){
}
执行操作:
将该文件编译后放到home/yiran(可自定义) 下
找到etx/init.d 下的rc 文件 vi 打开 修改在Path下添加如下路径:/home/yiran/logd(logd为上述文件编译后的文件名)
保存退出
reboot Linux
用 ps -ef | more 便可查到自己的写的守护进程。小一建议:
1:进程号靠前,多按几次空格。
2:代码里的5行注释比较重要。
0 0
- Linux 学习第一篇
- Linux学习第一篇
- Linux学习第一篇
- Linux 学习第一篇
- Linux 学习第一篇
- arm linux中断机制学习第一篇
- linux 设备驱动学习------第一篇
- Linux学习第一篇--安装CentOS7
- linux学习第一篇:网络配置
- 第一篇 UCOS介绍
- linux学习第一篇:在VirtualBox下安装linux操作系统
- 第一篇:linux op
- Linux 入门第一篇
- servlet学习(第一篇)
- 多线程学习第一篇
- 第一篇学习日记
- 第一篇PHP学习
- android 学习第一篇
- 使用==操作符比较float类型的话到…
- Java字符串问题盘点(JKD6) 如…
- 数据库表死锁解决方案
- oracle中的exists 用法以及效…
- 抽象工厂模式
- Linux 学习第一篇
- Http bad file descriptor
- Dubbo架构设计详解
- Vim插件之vim-polyglot
- Extjs关于tabpanel的 bug修改
- jxl 对excel的日期处理及中文乱码
- 存储过程,数组游标
- JDBC获取oracle日期类型
- JS获取上个月日期函数