Creating a daemon in Linux

0 votes

In Linux I want to add a daemon that cannot be stopped and which monitors filesystem changes. If any changes are detected, it should write the path to the console where it was started plus a newline.

I already have the filesystem changing code almost ready but I cannot figure out how to create a daemon.

My code is from here: http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html

What to do after the fork?

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

  pid_t pID = fork();
  if (pID == 0)  {              // child
          // Code only executed by child process    
      sIdentifier = "Child Process: ";
    }
    else if (pID < 0) {
        cerr << "Failed to fork" << endl;
        exit(1);
       // Throw exception
    }
    else                                   // parent
    {
      // Code only executed by parent process

      sIdentifier = "Parent Process:";
    }       

    return 0;
}

Apr 21, 2022 in Linux Administration by Edureka
• 13,670 points
188 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

0 votes
1 answer

How to create a symlink in Linux?

To create a symbolic link, you can ...READ MORE

answered Feb 1, 2019 in Linux Administration by Omkar
• 69,210 points
825 views
0 votes
1 answer

generating a list of files with their absolute path in Linux

If you find an absolute path to start with, ...READ MORE

answered May 16, 2019 in Linux Administration by Upasana
• 8,620 points
1,119 views
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 21, 2019 in Linux Administration by DareDev
• 6,890 points
753 views
0 votes
1 answer

Error:mvn clean install" in my linux machine to build a maven Project

Hello @Niroj , You need to double check the PATH environment ...READ MORE

answered Aug 6, 2020 in Linux Administration by anonymous
• 82,880 points
2,748 views
0 votes
1 answer

How to check permissions of a file in the Linux system?

Hi@akhtar, If you prefer using the command line, ...READ MORE

answered Aug 13, 2020 in Linux Administration by MD
• 95,440 points
1,459 views
0 votes
1 answer

How to check permissions of a folder in the Linux system?

Hi@akhtar, You can use ls command to check ...READ MORE

answered Aug 13, 2020 in Linux Administration by MD
• 95,440 points
8,894 views
0 votes
1 answer

How to give the read power of a folder in Linux system?

Hi@akhtar, You can use chmod command in your ...READ MORE

answered Aug 13, 2020 in Linux Administration by MD
• 95,440 points
652 views
0 votes
1 answer

How to remove write permission from a folder in Linux system?

Hi@akhtar, You can use chmod command to remove ...READ MORE

answered Aug 13, 2020 in Linux Administration by MD
• 95,440 points
2,961 views
0 votes
1 answer

How to create a group in Linux system?

Hi@MD, On Linux, group information is held in the /etc/group file. ...READ MORE

answered Aug 14, 2020 in Linux Administration by akhtar
• 38,230 points
577 views
0 votes
1 answer

How to add user to a group in Linux system?

Hi@akhtar, In Linux, different users have different roles ...READ MORE

answered Aug 14, 2020 in Linux Administration by MD
• 95,440 points
510 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP