how to run a killed process

hi,
i am creating a daemon process for updating the file at regular interval.one problem with this is if anybody kills the daemon it wont update the file.anybody have idea how to rerun the daemon if it killed.the code is written in c++ in solaries environment.

thnaks & regards
suresh

Does the function have a signal handler? That will stop some kill commands - but not all signals are trappable.

One way is to run a script from crontab periodically to check for the presence of the daemon, and rerun it if it has been bumped off.

Normally daemons are run from a protected account, one that only root can su to for example. This stops random acts of aggression against your daemon.

If you are running Solaris 10 or newer, you can use the SMF framework to have your daemon restarted automatically.

Add an entry into /etc/inittab for your process and let the init process keep your daemon running. That's what it's for.

jlliagre is right - It is no longer necessary to edit the /etc/inittab file directly. Administrators should use the Solaris Service Management Facility (SMF) to define services instead. Refer to smf(5) and the System Administration Guide: Basic Administration for more information on SMF.

Why?

SMF is much more difficult to understand and manage than one line in /etc/inittab, and SMF is non-portable. Knowing how to apply the functionality of init and inittab is useful on Linux and Solaris and probably AIX, HP-UX, BSD, and Apple's OS X.

PS - Please don't quote the work of others without attribution. Your post is lifted verbatim from the contents of /etc/inittab and the contents of "man inittab" on Solaris:

# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# The /etc/inittab file controls the configuration of init(1M); for more
# information refer to init(1M) and inittab(4).  It is no longer
# necessary to edit inittab(4) directly; administrators should use the
# Solaris Service Management Facility (SMF) to define services instead.
# Refer to smf(5) and the System Administration Guide for more
# information on SMF.
#
# For modifying parameters passed to ttymon, use svccfg(1m) to modify
# the SMF repository. For example:
#
#       # svccfg
#       svc:> select system/console-login
#       svc:/system/console-login> setprop ttymon/terminal_type = "xterm"
#       svc:/system/console-login> exit
#
#ident  "@(#)inittab    1.42    05/06/10 SMI"
ap::sysinit:/sbin/autopush -f /etc/iu.ap
sp::sysinit:/sbin/soconfig -f /etc/sock2path
smf::sysinit:/lib/svc/bin/svc.startd    >/dev/msglog 2<>/dev/msglog </dev/console
p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog
pt:s1234:powerfail:/usr/lib/svc/method/installupdates lock

And

Reformatting page.  Please Wait... done

File Formats                                           inittab(4)

NAME
     inittab - script for init

DESCRIPTION
     The /etc/inittab file controls process dispatching by  init.
     The processes most typically dispatched by init are daemons.

     It is no longer necessary  to  edit  the  /etc/inittab  file
     directly.  Administrators  should  use  the  Solaris Service
     Management Facility (SMF) to define services instead.  Refer
     to smf(5) and the  for more information on SMF.

But once the daemon killed more than 5 times, it won't start again by inittab.
Solaris will write "off" into this entry under /etc/inittab.

Three comments:

  • I wrote "you can use", not "you must use".

  • This is the Solaris forum so non portability might not be an issue. Moreover, SMF is certainly portable and open sourced. It just happen not having being ported to other platforms.

  • SMF has much more features than inittab in term of dependencies/monitoring/debugging/administration/configuration repository/snapshots so worth being considered.

2nd field is runlevel..so as long as it is on that runlevel it will start.you need to make action field as "respawn".