2.守护进程
用C语言编写一个程序,在该程序中创建守护进程,守护进程具有以下三个功能:
(1)每十五分钟弹出窗口提示用户已连续使用电脑十五分钟,提醒用户注意休息。提示:可以用SDL编程实现窗口文本显示提醒信息,信息以红色字体显示,或者用自己喜欢的图形显示提醒信息。
(2)守护进程每隔一个指定的时间去检查邮箱,如果发现有邮件了,提示有新邮件到达(播放提示音或在屏幕上显示有新邮件到达)。Linux 的默认的个人邮箱地址是 /var/spool/mail/用户的登陆登录名。
(3)守护进程每隔10秒向/tmp目录中的日志文件“你的学号.log”中写入系统的运行状态,然后写入“你的学号监控的系统状态”文字和当前的系统时间。注:这里“你的学号”请替换为你自己的真实学号
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<fcntl.h>
#include<SDL.h>
#include<SDL_ttf.h>
#include<dirent.h>
#include<time.h>
int main(){
pid_t child1,child2,child3;
struct stat buf;
int i,j=0;
time_t t;
DIR *dir;
struct dirent *ptr;
SDL_Surface *screen,*text;
SDL_Color red={
255,0,0,0};
TTF_Font *Nfont;
SDL_Rect drect;
int stat;
FILE *fp;
child1=fork();
if(child1>0)
exit(0);
else if(child1<0)
{
perror("创建子进程失败"