Sponsored Content
Full Discussion: Background service!
Operating Systems HP-UX Background service! Post 302070433 by buffoonix on Tuesday 4th of April 2006 07:08:05 PM
Old 04-04-2006
Services on Unix are usually called daemons
because they silently and diligently run in the background for long periods
(mostly until next system reboot) and service clients (however the roles may
also be changed) thus acting like benign leprechauns contrary to malign demons
(note the different spelling).
To achieve this daemons in the traditional way fork after they have started.
This means they make an exact copy of their process also inheriting the environment
as well as file descriptors etc.
If you issue man fork you will notice that this is also the name of a Unix system library call.
Btw, you may already have come across Beastie the BSD mascot.
As can be easily realized Beastie is the incorporation of a Unix daemon with a fork in its hand.
Once a daemon has forked it would exit its parent process,
change directory to / (or into chroot), not to block other mounts,
close unused file descriptors, and do other prepatory cleanup or initialization work.
Finally to really background it would need to dissociate from any controlling terminal
by starting a new session through the setsid syscall.
In BSD style syntax you could issue ps x to get a list of all background processes.
If you started a process from an interactive shell with an appended ampersand &,
although it would background, you would still reap it if you exited your shell because on exit the shell (or the system) would send a hangup signal to all its backgrounded processes.
To avoid this you would also have to prepend a nohup before your startup command.
If you were using a Bash shell however you could still use the disown command for a merely backgrounded but not nohupped process (see man bash).
 

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

background jobs

Hi, i have a problem with turning a job into backgrund. When i enter this at the shell: spice -b darlington.cir -r output.raw > screenout.tmp & and then let me show the currently running jobs, i get the following output: + Suspended (tty output) spice -b darlington.cir -r output.raw >... (4 Replies)
Discussion started by: qsi
4 Replies

2. Shell Programming and Scripting

background process

Hello, This has probably been answered in other forms, however I would like to confirm this statement before I use it in production. Will this syntax work for a background process? echo "nohup server_process1 >/dir1/nohup.server_process1 2>&1 &" | ksh Please advise. Thanks (1 Reply)
Discussion started by: jerardfjay
1 Replies

3. AIX

Background process

how to check the process running in background? how can i run a process in background? pls explain with commands (1 Reply)
Discussion started by: udtyuvaraj
1 Replies

4. UNIX for Beginners Questions & Answers

Run one service after another service has finished - systemd

Hi all I would like to know how to run task2.service after task1.service has finished. task1.service has a timer (task1.timer), that makes it run every 5 minutes OnCalendar=*:0/5task2.service is basically a script, that has to work on the files created after task1 has finished. This is what I... (2 Replies)
Discussion started by: guilliber
2 Replies
DAEMON(3)						     Linux Programmer's Manual							 DAEMON(3)

NAME
daemon - run in the background SYNOPSIS
#include <unistd.h> int daemon(int nochdir, int noclose); DESCRIPTION
The daemon() function is for programs wishing to detach themselves from the controlling terminal and run in the background as system dae- mons. Unless the argument nochdir is non-zero, daemon() changes the current working directory to the root ("/"). Unless the argument noclose is non-zero, daemon() will redirect standard input, standard output and standard error to /dev/null. RETURN VALUE
(This function forks, and if the fork() succeeds, the father does _exit(0), so that further errors are seen by the child only.) On success zero will be returned. If an error occurs, daemon() returns -1 and sets the global variable errno to any of the errors specified for the library functions fork(2) and setsid(2). SEE ALSO
fork(2), setsid(2) NOTES
The glibc implementation can also return -1 when /dev/null exists but is not a character device with the expected major and minor numbers. In this case errno need not be set. HISTORY
The daemon() function first appeared in BSD4.4. BSD MANPAGE
1993-06-09 DAEMON(3)
All times are GMT -4. The time now is 07:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy