Return to Snippet

Revision: 1811
at November 10, 2006 00:00 by whitetiger


Updated Code
#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
	/*
	 * Funzione che mi crea un demone
	 */
	
	int pid;
	
	// create - fork 1
	if(fork()) return 0;

	// it separates the son from the father
	chdir("/");
	setsid();
	umask(0);

	// create - fork 2
	pid = fork();

	if(pid)
	{
		printf("Daemon: %d\n", pid);
		return 0;
	}
	
	/****** Codice da eseguire ********/	
	FILE *f;

	f=fopen("/tmp/coa.log", "w");
	
	while(1)
	{
		fprintf(f, "ciao\n");
		fflush(f);
		sleep(2);
	}
	/**********************************/
}

Revision: 1810
at November 9, 2006 23:55 by whitetiger


Initial Code
#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
	/*
	 * Funzione che mi crea un demone
	 */
	
	int pid;
	
	// create - fork 1
	if(fork()) return 0;

	// it separates the son from the father
	chdir("/");
	setsid();
	umask(0);

	// create - fork 2
	pid = fork();

	if(pid)
	{
		printf("Daemon: %d\n", pid);
		return 0;
	}
	
	/****** Codice da eseguire ********/	
	FILE *f;

	f=fopen("/tmp/coa.log", "w");
	
	while(1)
	{
		fprintf(f, "ciao\n");
		fflush(f);
		sleep(2);
	}
	/**********************************/
}

Initial URL

                                

Initial Description

                                

Initial Title
C - create Process Daemon

Initial Tags
http, math, python, c, perl

Initial Language
C++