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 8482497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:50:50+00:00 2026-06-10T19:50:50+00:00

I have put together a small bash script that launches then periodically checks if

  • 0

I have put together a small bash script that launches then periodically checks if my main program is running (console application, no gui). My main application is supposed to be the guts of an appliance (embedded) system and it needs to run continuously.

# Start myProgram
   /path/to/myProgram &

while true
do
   if [  -n "`ps ax | grep -v grep | grep myProgram`" ]
   then
       sleep 5 2>&1 > /dev/null
   else
      /path/to/myProgram &
   fi
done

My main program contains a c++ select() (with timer) loop that watches several TCP, UDP and Unix Domain sockets as well as stdin.

When run in the foreground, myProgram run as expected. When no one sends it data it just sits in the select() times out every 2 seconds, fiddles with timers and such, then waits again. Any keyboard activity ending with an ENTER is grabbed and processed. Console input puts up a “N bytes received at console” message (for now!)

When my script launches myProgram in the background, however, I get a constant stream of “) bytes received at console” messages as if stdin were closing and reopening or some other app is sending a stream of ENTERs to my app.

Could someone explain please?

If, in fact, the state of being in the background is causing stdin to close/reopen ovr and over, is it possible for myProgram to detect that it is backgrounded and disconnect from stdin? Will I need to disconnect from stdout and stderr as well? Guess that’d make me a daemon.

And, lastly, would the watchdog program be a better way to track that myProgram is still running? Can watchdog restart the program rather than restarting the whole machine?

  • 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-10T19:50:52+00:00Added an answer on June 10, 2026 at 7:50 pm

    Only foreground jobs can have standard input attached to the terminal. Background jobs are suspended if they attempt to read from the terminal. You’ll have to leave the job in the foreground, or redirect standard input from somewhere else.

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

Sidebar

Related Questions

I have a really small app that I put together in VS 2008 Express
I just put together a small script for a team of users that collects
I have put together a script where the main image loads once clicked on
I have put together a small ASP.NET MVC 2 site that does some very
I have MANY small Test Projects where I put together just enough code to
I have put together an API that responds to a POST request by putting
Last night I tried to put together something that I have had working since
We've put together an app that is mostly working in phonegap. We have an
I have put together a small contacts management app in php for my personal
If I have output from two sources that I want to put together on

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.