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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:52:26+00:00 2026-05-13T07:52:26+00:00

In a UNIX-y way, I’m trying to start a process, background it, and tie

  • 0

In a UNIX-y way, I’m trying to start a process, background it, and tie the lifetime of that process to my shell.

What I’m talking about isn’t simply backgrounding the process, I want the process to be sent SIGTERM, or for it to have an open file descriptor that is closed, or something when the shell exits, so that the user of the shell doesn’t have to explicitly kill the process or get a “you have running jobs” warning.

Ultimately I want a program that can run, uniquely, for each shell and carry state along with that shell, and close when the shell closes.

IBM’s DB2 console commands work this way. When you connect to the database, it spawns a “db2bp” process, that carries the database state and connection and ties it to your shell. You can connect in multiple different terminals or ssh connections, each with its own db2bp process, and when those are closed the appropriate db2bp process dies and that connection is closed.

DB2 queries are then started with the db2 command, which simply hands it off to the appropriate db2bp process. I don’t know how it communicates with the correct db2bp process, but maybe it uses the tty device connected to stdin as a unique key? I guess I need to figure that out too.

I’ve never written anything that does tty manipulation, so I have no clue where to even start. I think I can figure the rest out if I can just spawn a process that is automatically killed on shell exit. Anyone know how DB2 does it?

  • 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-13T07:52:26+00:00Added an answer on May 13, 2026 at 7:52 am

    If your shell isn’t a subshell, you can do the following; Put the following into a script called “ttywatch”:

    #!/usr/bin/perl
    my $p=open(PI, "-|") || exec @ARGV; sleep 5 while(-t); kill 15,$p;
    

    Then run your program as:

    $ ttywatch commandline... & disown
    

    Disowning the process will prevent the shell from complaining that there are running processes, and when the terminal closes, it will cause SIGTERM (15) to be delivered to the subprocess (your app) within 5 seconds.

    If the shell isn’t a subshell, you can use a program like ttywrap to at least give it its own tty, and then the above trick will work.

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

Sidebar

Related Questions

Using UNIX socket APIs on Linux, is there any way to guarantee that I
I have a command that works one way in OSX/Unix and another in Debian/Linux.
I noticed that strtotime() handles unix timestamps in an odd way, and I was
Is there a way to log(/var/log) commands executed by users in the Unix shell?
Is there a way that I can use Python on Windows to execute shell
Is there a way to use unix date to print the number of seconds
I'm looking for a way to get notified in my unix system for new
What is recommended way to keep a user configuration data in Unix/Linux? My programming
What would be an elegant way of comparing 2 symbolic links in Unix? Assume
Is there a way to get the instruction pointer of a running application Unix?

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.