Exemplo n.º 1
0
int Task::Start(u_int32_t uiProcessNum, u_int32_t uiRate, bool bByTaskIdx)
{
	signal(SIGCHLD, SIG_IGN);
	
    if(0 == uiProcessNum)
		uiProcessNum = 1;

	if(uiRate > 0)
		m_cFMgr.Open(uiRate);

	m_uiRate = uiRate;
	
	for(unsigned int i = 1; i <= uiProcessNum; i++)
	{
	    int iPid = fork();
		if(0 == iPid)
		{
		    InitDaemon();
			
		    DoStart(i, bByTaskIdx);
			
		    exit(0);
		}
		else if(iPid < 0)
		{
		    BOSS_ERROR("fork %d error: %s", i, strerror(errno));
		}
	}

	return 0;
}
Exemplo n.º 2
0
int main()
{
	InitDaemon();

	FILE * pf = fopen("PidStore.txt","w");
	fprintf(pf,"%d\n",getpid());
	fclose(pf);	

	s[0] = (Sensor *)malloc(sizeof(Sensor));
	s[1] = (Sensor *)malloc(sizeof(Sensor));
	s[2] = (Sensor *)malloc(sizeof(Sensor));
	s[3] = (Sensor *)malloc(sizeof(Sensor));
	s[4] = (Sensor *)malloc(sizeof(Sensor));
	s[0]->relaySta = s[1]->relaySta = s[2]->relaySta = s[3]->relaySta = CLOSE;
	ctlSta = AUTO;

	signal(SIG_SET,Action);
	signal(SIG_GET,Action);
	
	int counter = 0;
	
	env = (Env *) malloc(sizeof(Env));
	env->temp = env->humid = env->illumi = \
	env->thres.tempH = env->thres.tempL = env->thres.humidH = env->thres.humidL =\
	env->thres.illumiH = env->thres.illumiL = 0;
	while(1)
	{
		g_Sensor_status * sstatus = (g_Sensor_status *)malloc(sizeof(g_Sensor_status));
		FILE * flog = fopen("AutoMachine.log","ab+");
		fprintf(flog,"%dth loops...\n",counter);
		fclose(flog);
		GetData(sstatus);
		UpdateEnv(sstatus,env);

		counter++;
		/*
		if(counter % 1200 == 0)
		{
			WriteFile("exchange.txt",env);
			OutputEnv();	
		}
		else
		{
			if(counter >= 12000)
			{
				unlink("exchange.txt");
				counter = 0;
			}
		}*/
		if(counter < 180)
		{
			WriteFile("exchange.txt",env);
			OutputRFID("rfid.txt",sstatus);
			OutputEnv();	
		}
		else
		{
				unlink("exchange.txt");
				unlink("AutoMachine.log");
				unlink("env.txt");
				unlink("rfid.txt");
				counter = 0;
		}

		if(ctlSta == AUTO)
			AutoControl(sstatus,env,s);
	
		//SynRelay();
		free(sstatus);
			
		sleep(1);		
	}
	unlink("/web/clientfifo");
	unlink("/web/serverfifo");
	free(env);
	return 0;
}
Exemplo n.º 3
0
int main( int argc, char **argv )
{
	//版本查询
	if(1 < argc && !strcasecmp(argv[1], "-v" ))
	{
		printf("%s Epoll Server Ver: 3.0.9 build in %s %s\n\n",SVR_NAME,  __DATE__, __TIME__);

		printf("--------------[log]-----------------\n");
		printf("[2014-02-08] v3.0.9 [f] aux thread close socket when it does not monitor the socket\n");
		printf("[2013-04-03] v3.0.8 [a]patxiao frequency log\n");
		printf("[2013-03-15] v3.0.7 [a]patxiao support close port link\n");
		printf("[2012-11-06] add level log\n");
		printf("[2012-11-06] add error msg for exeption close link\n");
		printf("[2012-04-10] support uniqueID for mq file: key={proj_id+FF+uniqueID}\n");
		printf("[2011-09-01] support ip table access/deny\n");
		printf("[2011-07-20] support admin so\n");
		printf("[2011-05-11] if setrlimit failed, exit!\n");
		printf("[2011-03-16] add mutil thread, mutil cq ,mutil port.\n");
		printf("[2010-11-30] delete tcp nagle to solve 'the last pkg slow' problem.\n");
		exit(0);
	}

	if(argc < 2)
	{
		printf("%s  [config]\n", argv[0]);
		printf("%s  [config] -d\n", argv[0]);
		printf("%s  -v\n", argv[0]);
		exit(0);
	}
	
	//进程互斥锁
	int lock_fd = open(argv[1], O_RDWR|O_CREAT, 0640);
	if(lock_fd < 0 )
	{
		printf("Open Lock File Failed,Server Init Failed!\n");
		return -1;
	}

	int ret = flock(lock_fd, LOCK_EX | LOCK_NB);
	if(ret < 0 )
	{
		printf("Lock File Failed,Server is already Running!\n");
		return -1;
	}

	//后台
	if((argc>=3) && (0 == strcasecmp(argv[2], "-d")))
	{
		;
	}
	else
	{
		InitDaemon();
	}

	//自定义信号
	signal(SIGUSR1, sigusr1_handle);
	signal(SIGUSR2, sigusr2_handle);	

	char szProcName[128];
	GetNameFromPath(argv[0],szProcName);
	
	char szTmp[128];	
	sprintf(szTmp,"../log/%s",szProcName);
	TLib_Log_LogInit(szTmp, 0x10000000, 5);

	TLib_Log_LogMsg("===== %s begin Start... =====\n",SVR_NAME);
	g_pMainCtrl = new CMainCtrl();

	ret = g_pMainCtrl->Initialize(szProcName,argv[1]);
	if( 0 != ret )
	{
		exit(0);
	}
	
	TLib_Log_LogMsg("===== %s Started. =====\n",SVR_NAME);
	g_pMainCtrl->Run();
	return 0;
}