#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>

main()
{
	FILE *fp;
	int i;
	char *start_date;
	time_t now;
	pid_t pid = 0;

	if( fork() ) exit(0);

	fclose(stdin);
	fclose(stdout);
	fclose(stderr);

	if( chdir("/u2/system/dwmalone/www") ) exit(1);
	if((fp=fopen("count.pid","r")) && (fscanf(fp,"%d",&pid)==1) && !kill(pid,0)) exit(0);
	if(fp) close(fp);
	if( !(fp=fopen("count.pid","w")) ) exit(3);
	fprintf(fp,"%d\n",getpid());
	fclose(fp);

	now = time(NULL);
	start_date = ctime(&now);
	for( i = 1  ; ; i++ )
	{
		if( (fp = fopen("count.html","w")) == NULL ) exit(4);
		fprintf(fp,"<HTML>");
		fprintf(fp,"<HEAD><TITLE>David's Counting Page</TITLE></HEAD>");
		fprintf(fp,"<BODY>");
		fprintf(fp,"<H2>Named Pipes vs. CGI</H2>");
		fprintf(fp,"You are person number %d to read this since ",i);
		fprintf(fp,start_date);
		fprintf(fp,"I dunno why people don't use more named pipes.");
		fprintf(fp,"</BODY>");
		fprintf(fp,"</HTML>");
		fclose(fp);
		sleep(3);
	}
}

