#include
#include
#include
#include
#include
#include
#include
#define MAXFILE 65535
int main()
{
pid_t pc,sid;
int i,fd,len;
char *buf="This is a Dameon \n";
len=strlen(buf);
pc=fork();
if(pc<0)
{
perror("fork errror!");
exit(1);
}
else if(pc>0)
exit(0);
openlog("dema_update",LOG_PID,LOG_DAEMON);
syslog(LOG_ERR, "%s\n", "setsid");
if((sid=setsid())<0)
{
syslog(LOG_ERR,"%s\n","setsid");
exit(1);
}
if((sid=chdir("/"))<0)
{
syslog(LOG_ERR,"%s\n","chdir");
exit(1);
}
umask(0);
for(i=0;i close(i);
while(1)
{
if((fd=open("/tmp/dameon.log",O_CREAT|O_WRONLY|O_APPEND,0600))<0)
{
syslog(LOG_ERR,"open");
exit(1);
}
write(fd, buf, len+1);
close(fd);
sleep(10);
}
closelog();
exit(0);
}
阅读(1470) | 评论(0) | 转发(0) |