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

  • SEARCH
  • Home
  • 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 8598165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:05:24+00:00 2026-06-12T01:05:24+00:00

We have a custom C++ daemon application that forks once. So we’ve been doing

  • 0

We have a custom C++ daemon application that forks once. So we’ve been doing this in our Upstart script on Ubuntu 12.04 and it works perfectly:

expect fork
exec /path/to/the/app

However now we need to pass in an argument to our app which contains the number of CPUs on the machine on which it runs:

cat /proc/cpuinfo | grep processor | wc -l

Our first attempt was this:

expect fork
exec /path/to/the/app -t `cat /proc/cpuinfo | grep processor | wc -l`

While that starts our app with the correct -t value, Upstart tracks the wrong pid value, I’m assuming because those cat, grep & wc commands all launch processes in exec before our app.

I also tried this, and even it doesn’t work, I guess because setting an env var runs a process? Upstart still tracks the wrong pid:

expect fork
script
    NUM_CORES=32
    /path/to/the/app -t $NUM_CORES
end script

I’ve also tried doing this in an env stanza but apparently those don’t run commands:

env num_cores=`cat /proc/cpuinfo | grep processor | wc -l`

Also tried doing this in pre-start, but env vars set there don’t have any values in the exec stanza:

pre-start
    NUM_CORES=32
end script

Any idea how to get this NUM_CORES set properly, and still get Upstart to track the correct pid for our app that forks once?

  • 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-06-12T01:05:25+00:00Added an answer on June 12, 2026 at 1:05 am

    It’s awkward. The recommended method is to write an env file in the pre-start stanza and then source it in the script stanza. It’s ridiculous, I know.

    expect fork
    
    pre-start script
        exec >"/tmp/$UPSTART_JOB"
        echo "NUM_CORES=$(cat /proc/cpuinfo | grep processor | wc -l)"
    end script
    
    script
        . "/tmp/$UPSTART_JOB"
        /path/to/app -t "$NUM_CORES"
    end script
    
    post-start script
        rm -f "/tmp/$UPSTART_JOB"
    end script
    

    I use the exec line in the pre-start because I usually have multiple env variables and I don’t want to repeat the redirection code.

    This only works because the ‘. ‘ command is a built-in in dash and thus no process is spawned.

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

Sidebar

Related Questions

I'm working at a helpdesk application where i have a standalone script that queries
I have custom assembly that is loaded on runtime. at this point i have
I have a Swing application that is heavy customised with a lot of custom
I have custom Application class in my Android project that is properly described in
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have custom event that has several different subscribers who will all use the
I have custom gallery. Gallery represents items that are frame layout. There are one
I have custom component that I can place in my layout file (XML) for

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.