#include <sdtio.h>
#include <stblib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MAXDILE 65535
int main()
{
int i,fd;
pid_t pid;
char *buf = "hello,dameon";
int len = strlen(buf);
//first boot create child pid
pid = fork();
if(pid < 0)
{
perror("eeror\n");
exit(1);//error exit
}
else if(pid > 0)
{
exit(0);
}
//second create huihua
setsid();
//third change pwd
chdir("/");
umasl(0);
for(i = 0;i < MAXDILE;i++)
{
close(i);
}
while(1)
{
fd = open("/mnt/hgfs/dameon.log",O_CREAT|O_WRONLY,0600);
if(fd < 0)
{
perror("open");
exit(1);
}
write(fd,buf,len+1);
close(fd);
}
return 0;
}