只能起一个进程 LINUX

代码
/*
 * main.cpp
 *
 *  Created on: Feb 9, 2010
 *      Author: weiyu wang
 
*/

#include 
<signal.h>
#include 
<unistd.h>
#include 
<sys/types.h>
#include 
<sys/wait.h>
#include 
<semaphore.h>
#include 
<fcntl.h>

#include 
"awtools.h"
#include 
"awlogger.h"
#include 
"qmcontroller.h"

using namespace std;
using namespace AWTookit;

sem_t
* sem;

void sig_proc(int sig)
{
    signal(SIGINT, SIG_DFL);

    AWLOG_INFO(
"Ctrl + C, quit controller ......");

    sem_post(sem);

    exit(
0);
}

int main(int argc, char** argv) {

    signal(SIGINT, sig_proc);

    AWLOG_INIT(
"qmcontroller");

    sem 
= sem_open("qmanager", O_CREAT, 06441);

    
if (-1 == sem_trywait(sem))
        
return 0;

    controller().run();

    sem_post(sem);

    
return 0;
}




posted @ 2010-06-26 03:44  史莱姆  阅读(398)  评论(0编辑  收藏  举报