- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: disassociate controll terminal
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 09:56 AM
02-05-2003 09:56 AM
I am trying to run a script and to disassociate it from a terminal, so that the script thinks it is not run interactively. Is there any way to do it with just Unix command and without C-code ( I can use ioctl call with C, but I am not allowed to use C-code).
Thanks,
Vlad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 10:27 AM
02-05-2003 10:27 AM
Re: disassociate controll terminal
try doing:
nohup your_command &
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 02:57 PM
02-05-2003 02:57 PM
Re: disassociate controll terminal
For debugging, you might elect to redirect output somewhere, since it will be lost in the "nohup" disconnect from the parent process. But the basic form Melvyn describes is commonly used for this, and should work for you.
--bmr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 03:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 03:08 PM
02-05-2003 03:08 PM
Re: disassociate controll terminal
http://hpux.cict.fr/hppd/hpux/Sysadmin/screen-3.9.8/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 03:12 PM
02-05-2003 03:12 PM
Re: disassociate controll terminal
If you're going to use nohup, then also make sure to attach standard input, output, and error to the bit bucket. Otherwise the script will inherit the terminal.
nohup script /dev/null 2>&1 &
I find it more convenient to invoke non-interactive scripts as batch jobs:
batch <
EOF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 03:14 PM
02-05-2003 03:14 PM
Re: disassociate controll terminal
a c-shell script s1.csh is doing "tty -s" check to see if it is interactive.
the 2nd shell script s2.sh calls s1.csh, but s1.csh senses that it is interactive and does things as if it was interactive. I want it to think that it is a noninteractive call. I found one way to do it (very dirty). I created a THIRD script s3.sh and in it I do "sh s2.sh &". Now s1.csh thinks it is NOT interactive. Is there a cleaner way? If I do "sh s2.sh &" from a command line, it thinks it is interactive again. Any idea about a CLEAN way of doing it?
Thanks,
Vlad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 04:29 PM
02-05-2003 04:29 PM
Re: disassociate controll terminal
P
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2003 05:44 PM
02-05-2003 05:44 PM
Re: disassociate controll terminal
To determine if a script is running with a controlling tty, you can either ask the shell if it is interactive or use the tty command:
if [ -o interactive ]
then
export INTERACTIVE=/sbin/true
else
export INTERACTIVE=/sbin/false
fi
if tty -s
then
export INTERACTIVE=/sbin/true
else
export INTERACTIVE=/sbin/false
fi
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2003 01:47 AM
02-06-2003 01:47 AM
Re: disassociate controll terminal
echo /path/to/script | batch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2003 02:09 AM
02-06-2003 02:09 AM
Re: disassociate controll terminal
I think the answer to your question has already been given by many others.
As posted, if you don't want to (or in fact are prevented from) using syscalls (n.b. in this case it'd be the setsid() call), then you append an Ampersand to have the shell dissociate the process from the terminal.
But then the backgrounded process will still respond to a SIGHUP (or rather the controlling shell will emit them to her forked children).
To prevent this you ought to prepend the command nohup.
If however you are "allowed" to run a Perl script then you can use Perl's adoption of setsid(), which makes writing daemons in Perl unbeatably easy.
first you fork(), then you exit the parent process (that's the one that received the child's PID as return code from fork()), and then you call the POSIX module's setsid()
e.g.
use POSIX 'setsid';
$pid = fork();
exit 0 if $pid;
setsid();
That's basically all that is required, although usually one would do accompaying cleanup like
chdir '/';
# reopen STDIN, STDOUT, STDERR
open STDIN 'open STDOUT '>/dev/null';
open STDERR '>&STDERR';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2003 02:13 AM
02-06-2003 02:13 AM
Re: disassociate controll terminal
of course this was meant:
open STDERR, '>&STDOUT';