English 中文(简体)
Cannot在开斋后发现 da木。
原标题:Cannot find daemon log after running a daemon

我的誓言就是:

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>

using namespace std;

#define DAEMON_NAME "vdaemon"

void process(){

    syslog (LOG_NOTICE, "Writing to my Syslog");
}   

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

    //Set our Logging Mask and open the Log
    setlogmask(LOG_UPTO(LOG_NOTICE));
    openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);

    syslog(LOG_INFO, "Entering Daemon");

    pid_t pid, sid;

   //Fork the Parent Process
    pid = fork();

    if (pid < 0) { exit(EXIT_FAILURE); }

    //We got a good pid, Close the Parent Process
    if (pid > 0) { exit(EXIT_SUCCESS); }

    //Change File Mask
    umask(0);

    //Create a new Signature Id for our child
    sid = setsid();
    if (sid < 0) { exit(EXIT_FAILURE); }

    //Change Directory
    //If we cant find the directory we exit with failure.
    if ((chdir("/")) < 0) { exit(EXIT_FAILURE); }

    //Close Standard File Descriptors
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    //----------------
    //Main Process
    //----------------
    while(true){
        process();    //Run our Process
        sleep(2);    //Sleep for 2 seconds
    }

    //Close the log
    closelog ();
}

我汇编了它。

gcc vdaemon.cpp -o vdaemon

并管理

./vdaemon 

接着,我到来。

shishir@dewsworld:~/daemon$ ps -A | grep --color= auto  "vdaemon"
 5060 ?        00:00:00 vdaemon

然后我没有记录

shishir@dewsworld:~/daemon$ dmesg | grep --color= auto  "Writing to my Syslog"
shishir@dewsworld:~/daemon$ 

我需要知道如何获得这一记录。

问题回答

请参看<代码>/var/log/messages 欲了解<代码>syslog/ daemon将写到哪里。 如果你在那里找不到你的话,那么你就应当看一下你的log子。 它可以抛弃LOG_NOTICE信息,或LOG_USER信息。 你们可以没收系统一级的log魔报告。

见<代码>/var/log/messages,应当有。 <编码>dmesg将按违约情况显示系统信息的缓冲

页: 1 页: 1





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签