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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:37:16+00:00 2026-06-18T21:37:16+00:00

2 questions: 1) Is there any Linux/Posix API to know if a process has

  • 0

2 questions:

1) Is there any Linux/Posix API to know if a process has been invoked as a background process?

linux> myprogram &

Can the code for myprogram detect that it has been invoked to run in the background (via &) ?

2) Is there any Linux/Posix API to make a process run in the background even if it has been started as a foreground process? I.E. somehow ‘detach’ from the shell at runtime.. (either detach itself from the shell completely, or run as a background process of the shell).

linux> myprogram
**** starting myprogram as a background job ****
linux>

The shell prompt should come right back to me since myprogram has detached from the shell and is running in the background

  • 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-18T21:37:17+00:00Added an answer on June 18, 2026 at 9:37 pm

    1) there are two ways to know whether a process in background

    1. have a signal handler for SIGTTIN /SIGTTOUT and do a non-blocking read/write depending on which signal handler(stdin/stdout).

    2. check the process-group and match it with the terminals’ getpgrp() == tcgetpgrp(STDOUT_FILENO)

    you will need to repeat the check, as the process can be foregrounded or backgrounded anytime.

    2) There is a daemon function to put the process in background. its advisable to redirect the application prints to syslog or some other file while daemonizing.

    if (daemonize) {
    //redirect all prints to syslog or some other logfile
        daemon(0, 0);
    }
    

    where daemonize can be an arguement to the application whether to go into background or not.

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

Sidebar

Related Questions

I know there are many questions similar but any of them didn't help. in
I have 3 questions about thread and process communication. Can the Linux function msgget(),
Actually I have two questions. (1) Is there any reduction in processing power or
Given my previous questions about the the usage of AMPL. Are there any other
Just a curious question but is there any programs that can help/aid you when
I know there are lot of questions like this in stack overflow, but i
there's a question: Is there any way to pair Bluetooth device in Windows programmatically?
This is a simple question : Is there any automatic indentation alignment on Eclipse
Simple question here: is there any way to convert from a jagged array to
Is there any difference between ReferencePath with condition '%(CopyLocal)'=='true' and ReferenceCopyLocalPaths ? The question

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.