Platinum Partner

C - Create Process Daemon

// Create a process Daemon


#include 
#include 

#include 
#include 

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);
	}
	/**********************************/
}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}