Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 773139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:55:03+00:00 2026-05-14T18:55:03+00:00

I have started a service daemon , by running the binary(written in C++) through

  • 0

I have started a service daemon , by running the binary(written in C++) through script file stored rc5.d .

But I am not sure how to capture the pid of the daemon process and store it in pid file in /var/run/.pid . So that I can use the pid for termination.
How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:55:04+00:00Added an answer on May 14, 2026 at 6:55 pm

    Try using start-stop-daemon(8) with the --pidfile argument in your init script. Have your program write its PID to a specified location (usually determined in a configuration file).

    What you have to look out for is stale PID files, for instance, if a lock file persisted across a reboot. That logic is best implemented in the init script itself, hence the --exec option to start-stop-daemon.

    E.g, if /var/run/foo.pid is 1234, and /proc/1234/exe isn’t your service, the lock file is stale and should be quietly removed, allowing the service to start normally.

    As far as your application goes, just make sure the location of the lockfile is configurable, and some means exists to tell the init script where to put it.

    For instance: (sample: /etc/default/foo) :

    PIDFILE=/var/run/foo.pid
    OTHEROPTION=foo
    

    Then in /etc/init.d/foo :

    [ -f /etc/default/foo ] && . /etc/default/foo
    

    Again, other than writing to the file consistently, all of this logic should be handled outside of your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have started research on Service Broker and planning to implement in application. But
I currently have a WCF Service Library which will be started through a Console
We are using Dtos in our WCF service interface, but have started to come
I have written a linux daemon that will be (and must be) running as
I have a particular situation: a service started by a broadcast receiver starts an
I started using emacs and slime to develop some little service. I have found
I have started implementing Subscriptions into my app but I cannot get the API
I have started prgramming a windows service. I have added a notify icon from
I have started using django very recently . I am building a service with
I always thought I understood how this works...but lately I have started really using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.