devil实验五Linux进程控制.docVIP

  • 103
  • 0
  • 约2.57千字
  • 约 5页
  • 2016-05-04 发布于重庆
  • 举报
devil实验五Linux进程控制

实验五 守护进程 实验目的 1.掌握守护进程的特点 2.掌握守护进程的程序设计方法。 实验内容 编写一程序,要求运行后成为守护进程,复制守护进程的子进程,子进程往某个文件(如test.txt)里写入字符串“测试守护进程:当前系统时间”。父进程等待子进程终止后向系统日志文件“/var/log/syslog”写入“子进程终止:当前系统时间”结束,守护进程的错误信息输出到系统日志文件。请把产生守护进程的部分分割成独立的程序文件。提示使用openlog函数和syslog,closelog函数。 要求: 守护进程两个源程序文件代码 //daemon.c #includestdio.h #includestdlib.h #includeunistd.h #includesignal.h #includesys/param.h #includesys/types.h #includesys/stat.h #includetime.h void init_daemon(){ int pid; int i; FILE *fp; time_t t; if(pid=fork()) exit(0); if((fp=fopen(./test.txt,a))=0){ t=time(0); fprintf(fp,测试守护进程:%s,asctime(localtime(t))); fclose(fp)

文档评论(0)

1亿VIP精品文档

相关文档