03-02-2008
Quote:
Originally Posted by
adderek
But in my opinion this is not a good thing.
I have the same opinion. To the kernel, the definition of a daemon is a process with no controlling terminal. Daemons show up with a ? in the tty field on most implementations of ps. When a daemon opens a tty, that tty becomes it's controlling terminal. It is no longer a daemon nor will any child processes be daemons. As one example of the many problems this will cause, if you type a control c on that terminal all processes with that controlling will get an INTR unless they are ignoring that signal.
You can avoid this by forking a subprocess to open the terminal, do the tty io, pass the data back to the parent via a file or pipe, and then exit. You must also ensure that this is completed prior to any login prompt appearing on the terminal.
This is why daemons fork to write a message on the console. Becoming a daemon again is not possible, but with the right sequence of operations including several forks(), a process can arrange for a descendant process to be created as a daemon.
Avoiding the non-daemon trap will still leave the problem that the user must be present at reboot time, but at least the system should be working.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
New in Unix, I am adding a line "route add 57.14.y.y 57.14.x.x" every day after rebooting the system. Where can I add the line so during boot up (the system is re-started every day by design (???) the line is executed? (I tried the /etc/rc2.d/S90 but for some reason the line needs to be added... (2 Replies)
Discussion started by: texaspanama
2 Replies
2. HP-UX
Hi,
I want a script to execute as soon as a user logs in(instead of directing to his home directory). i know that i have to mention the path of script in the user's .profile to execute this, but not sure where and what to edit. I just tried and was unsuccesful.
Kindly provide the code that i... (4 Replies)
Discussion started by: sridharr83
4 Replies
3. AIX
I am using AIX 5.3 in P6 machine.
I have a script "test.sh", when i run it manually it runs properly.
I want to run the script automatically when system starts.
I kept the script in /etc/rc.d/init.d and also in /etc/rc.d/rc2.d but it is not working.
Do i have to write it in inittab instead of... (1 Reply)
Discussion started by: pchangba1
1 Replies
4. UNIX for Dummies Questions & Answers
Hello there!
I need help.
Everytime I login to my ssh, i see this:
-bash: .export: command not found
-bash: .export: command not found
-bash: .export: command not found
-bash: .export: command not found
any help ?
thanks (0 Replies)
Discussion started by: fbauto1
0 Replies
5. AIX
Hi
I need the below script to be started whenever I reboot my aix server ?
#cat cdbegin
/cdirect/cdunix/ndm/bin/cdpmgr -i /cdirect/cdunix/ndm/cfg/cbspsdb01/initparm.cfg
Please suggest how to add this to the startup ? (2 Replies)
Discussion started by: samsungsamsung
2 Replies
6. Shell Programming and Scripting
Hello,
I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall:
I regularly need to delete files from many directories.
A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies
7. Shell Programming and Scripting
Hi all,
I'm writing a script to stop & start oracle:
su - oracle -c "sqlplus / as sysdba" -c "shutdown immediate">> ${log} 2>&1
The {log} refers to the log file. The part in bold gives error:
/usr/sbin/shutdown: Only root can run /usr/sbin/shutdown
Pls suggest how to correct this.
... (5 Replies)
Discussion started by: frum
5 Replies
8. Shell Programming and Scripting
I copied the script from an AskUbuntu post -
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat7
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO
... (14 Replies)
Discussion started by: Hijanoqu
14 Replies
9. Shell Programming and Scripting
I can't quite find a clear answer on how to properly write a start up script. Does anybody have any ideas?? (3 Replies)
Discussion started by: Huitzilopochtli
3 Replies
LEARN ABOUT NETBSD
login_tty
OPENPTY(3) BSD Library Functions Manual OPENPTY(3)
NAME
openpty, login_tty, forkpty -- tty utility functions
LIBRARY
System Utilities Library (libutil, -lutil)
SYNOPSIS
#include <util.h>
int
openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp);
int
login_tty(int fd);
pid_t
forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp);
DESCRIPTION
The openpty(), login_tty(), and forkpty() functions perform manipulations on ttys and pseudo-ttys.
The openpty() function finds an available pseudo-tty and returns file descriptors for the master and slave in amaster and aslave. If name is
non-null, the filename of the slave is returned in name. If termp is non-null, the terminal parameters of the slave will be set to the val-
ues in termp. If winp is non-null, the window size of the slave will be set to the values in winp.
The login_tty() function prepares for a login on the tty fd (which may be a real tty device, or the slave of a pseudo-tty as returned by
openpty()) by creating a new session, making fd the controlling terminal for the current process, setting fd to be the standard input, out-
put, and error streams of the current process, and closing fd.
The forkpty() function combines openpty(), fork(), and login_tty() to create a new process operating in a pseudo-tty. The file descriptor of
the master side of the pseudo-tty is returned (to the parent process only) in amaster. The filename of the slave is returned (to both the
parent and child processes) in name if name is non-null. The termp and winp parameters, if non-null, will determine the terminal attributes
and window size of the slave side of the pseudo-tty.
RETURN VALUES
If a call to openpty(), login_tty(), or forkpty() is not successful, -1 is returned and errno is set to indicate the error. Otherwise,
openpty(), login_tty(), and the child process of forkpty() return 0, and the parent process of forkpty() returns the process ID of the child
process.
FILES
/dev/[pt]ty[p-zP-T][0-9a-zA-Z]
ERRORS
openpty() will fail if:
[ENOENT] There are no available ttys.
[EPERM] The caller was not the superuser and the ptm(4) device is missing or not configured.
login_tty() will fail if ioctl() fails to set fd to the controlling terminal of the current process. forkpty() will fail if either openpty()
or fork() fails.
SEE ALSO
fork(2)
BSD
November 28, 2008 BSD