Operating System - HP-UX
1752805 Members
5534 Online
108789 Solutions
New Discussion юеВ

how to detach a process from the assigned tty?

 
SOLVED
Go to solution
Laurent Laperrousaz
Regular Advisor

how to detach a process from the assigned tty?

Hello,

Does anybody know how I can detach a process from its tty?

I can't find a way!

Laurent
9 REPLIES 9
John Meissner
Esteemed Contributor

Re: how to detach a process from the assigned tty?

could you give an example of what you mean?
All paths lead to destiny
David_246
Trusted Contributor

Re: how to detach a process from the assigned tty?

Sorry, not possible.
You could try the kill -HUP function, but please be carefull.

Regs David
@yourservice
John Meissner
Esteemed Contributor

Re: how to detach a process from the assigned tty?

If you are trying to output to a different tty you could use the write command

write 'message' tty
All paths lead to destiny
Umapathy S
Honored Contributor

Re: how to detach a process from the assigned tty?

Laurent,

I know this to do programmatically. Normally when daemons are created they will detach themselves from the tty which started it for they can run in the background, free from any signals from the tty, etc.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
A. Clay Stephenson
Acclaimed Contributor

Re: how to detach a process from the assigned tty?

If you mean, can you detach stdin, stdout, and stderr from a running process and somehow recoonect to another device - possibly /dev/null - then no this can't be done.

It is easy from the programming level. You use setsid(); it's one of the basic things you do to "daemonize" a process in C or Perl.

You can also look into the nohup command but all of these assume that you do this "on the front end" not after the process has been started.
If it ain't broke, I can fix that.
Massimo Bianchi
Honored Contributor

Re: how to detach a process from the assigned tty?

Hi,
depending on what do you want to do, you have two solution:

- if unattended: start your job with a "nohup" at the beginning and an "&" at the end. This ways it will continue to work even if the tty is closed.

- if attended: install a tool like "screen", it can attach and detach from its sessions.
ctrl-a,d detach from current session

screen -l reattach to a detached session.

see the man for more details...


Downloadable free from

http://hpux.connect.org.uk/


HTH,

Massimo
Massimo Bianchi
Honored Contributor

Re: how to detach a process from the assigned tty?

Laurent Laperrousaz
Regular Advisor

Re: how to detach a process from the assigned tty?

thanks everybody!

In fact what I want is to demonize a process launched at startup through /sbin/init.d/myprocess

It appeared that it starts but fails later because of inittab getty console init.

myprocess appears to be attached to the system console and it forks a lot of processes (all are then attached to the console). When getty init the console (that happens after init.d due to inittab sequence) all my processes stop!

I think the setsid() is the solution I will try to use it in a perl script and let you know how it works!
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: how to detach a process from the assigned tty?

Okay Laurent, now that I know what you are trying to do, I specnt about 2 minutes chopping up one of my Perl daemons. It has pretty much all the steps including a signal handler to exit when it receives a SIGTERM (kill -15).
If it ain't broke, I can fix that.