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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:12:51+00:00 2026-05-28T15:12:51+00:00

Possible Duplicate: In Linux, how to prevent a background process from being stopped after

  • 0

Possible Duplicate:
In Linux, how to prevent a background process from being stopped after closing SSH client

I have a C program which I access and interact with over terminal (usually from SSH on a linux box). I have been trying to find the solution to the problem where after I close the terminal/logout, the process ends with it (the program basically asks for some options then goes about its business with no further interaction required so I would like to have it continue to run even after I logout of SSH).

There are ways in linux to avoid this such as ‘screen’, but I want to do it programatically with C without relying on installed packages such as screen- even if this means reinventing the wheel.

So far I understand fork() to be the standard trivial way to daemonize a process, so could anyone help me to finish the code that allows the above described process to happen?

Within parent:

 main()
{

//Do interactive stuff

signal(SIGCHLD, SIG_IGN); //stops the parent waiting for the child process to end

if(fork())
 exit(0);
// and now the program continues in the child process

I can now logout of SSH which closes the original shell…and the child continues its work!

Within child:

//Continue with processing data/whatever the program does (no input/output to terminal required)
exit(0);
  • 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-28T15:12:52+00:00Added an answer on May 28, 2026 at 3:12 pm

    to detach the process from the parent:

    use setsid() on the children process, it will run the program in new session

     sid = setsid();
    

    To Keep a program running even when the terminal is closed:

    SIGHUP is a signal sent to a process when its controlling terminal is closed.

    try to ignore it using

    signal (SIGHUP, SIG_IGN);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to cross compile from Mac OS X to Linux x86? I
Possible Duplicate: Is a Linux executable compatible with OS X? I have some c++
Possible Duplicate: Maximum number of threads per process in Linux? just with some curiosity
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Starting iPhone app development in Linux? Is there a way to use
Duplicate: Run .NET exe in linux Hello, Is it possible to make my existing
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: How do you get assembler output from C/C++ source in gcc? Hello
Possible Duplicate: How can I create directory tree in C++/Linux? Why mkdir fails to

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.