程序运行些writeinfo

来源:互联网 发布:一般淘宝客服上班时间 编辑:程序博客网 时间:2024/06/04 23:35
void writeinfo(uint32_t id, const char * hostname){uint32_t curPid;curPid = getpid();    std::vector<std::string> strMsgs;    {        std::string strMsg;        base::sprintfex(strMsg, "%s - pid=%d, id=%d, hostname=%s\n", TimeStamp::now().format().c_str(), curPid, id, hostname);        strMsgs.push_back(strMsg);        FILE * fp = fopen("server.pid", "r");        if(fp)        {            for(size_t i = 0; i < MAX_WRITE_INFO-1 && !feof(fp); ++i)            {                char szMsg[1024] = {0};                fgets(szMsg, sizeof(szMsg), fp);                strMsgs.push_back(szMsg);            }            fclose(fp);        }    }    {        FILE * fp = fopen("server.pid", "w");        if(!fp)        {            ABORT_MSG("open file=%s,error=%s\n", "server.pid", strerror(errno));            return;        }        for(size_t i = 0; i < strMsgs.size(); ++i)        {            fwrite(strMsgs[i].c_str(), strMsgs[i].size(), sizeof(char), fp);        }        fclose(fp);    }}

0 0
原创粉丝点击