program that boots at OS startup

Hi All:
I wanted to know if i can write a program in UNIX, a program that does not run under a particular user login, but starts up at BOOT time.
Are there any online material that i could look into to do that.
Appreciate the help.
Thanks,
Preetham

Sure you can. It would help to know what OS you are running.

You will need to do a few things. All these things are based on an HPUX system. But should be similar to yours

You will need to edit the /etc/inittab file to add it to the bootup.

Create a script and put it in a directory similar to /sbin/init.d, may be diff place on your box.

Create a link to the startup directory similary to /sbin/rc3.d linked to the script in /sbin/init.d. The link name will start with an "S" and a number and the script name. Like S342myscript.

You will also need a Kill script in a lower directory probably in /etc/rc1.d. This script may be called K342myscript.

So you will have 3 files basically.

/sbin/init.d/myscript # actual script here
/etc/rc3.d/S342myscript # link to above script for startup on bootup.
/etc/rc1.d/K342myscript # link to above script for kill script on shutdown.

You can look at the syntax of other scripts in this file to include the "start" and "stop" functionality with your script so you can stop it and restart it when it gets out of whack.

Look at the /sbin/init.d/cron script. This is a fairly short example of a good script to copy. There should also be a template file in there as well.

Here are a few posts that give some help.

please note that all services run as a user. most services run as root. or whom ever you have it specified as.

a server still needs an environment to work in.

i havnt ever found a service that just starts as a unknown user or group.

Thanx,
i am using Redhat 7.2.
I am looking at writing a program that would listen at a particular socket and based on what it reads from the socket, it sends back some data(logic/program it does not matter..). what i basically would like to know is: given such a program xyz.c, how can i get it to run after the OS has Booted up. Are the any changes i need to make to the program.
i would like to know if i have to write a Kernal Program or module(im new to this kinda situation....All i know is to write a c program that does some socket operations). How must i compile this code and where should i place it.
I guess that the instructions you mentioned earlier is on how i could get the kernal to start and manage the application.
Thanks,
Preetham.

1) login and execute it. if you put it in the inetd.conf file then just HUP the inetd process.

2) use a compiler to make a binary from your c code. and Kelam answered the 2nd part to this question.

3) the tips we gave you are how you load a program at boot time.

4) i would suggest befor trying to make a prog. that listens to sockets and what not, you should familarize yourself with basic system administration so you will at least know if there is a problem where you can look and what not.

5) please (altho i now have my suspicion about this being a hacking related question) post legitimate questions.

Sounds like a hax0ring question, but here's to being helpful...
Since you have to be root to do this, I figure I'm not really aiding and abbetting...

The easiest way to start it up under Redhat Linux 7.* is to add the full path to the command in the /etc/rc.d/rc.local file.

thank you Optimus,
First, let me assure you that i have no intention of hacking, im not a hacker, can't afford to be one...i just code for food man :wink:

I have this hello world kernal module code:

/* Declare what kind of code we want from the header files */
#define __KERNEL__         /* We're part of the kernel */
#define MODULE             /* Not a permanent part, though. */

/* Standard headers for LKMs */
#include <linux/modversions.h> 
#include <linux/module.h>  

#define _LOOSE_KERNEL_NAMES
    /* With some combinations of Linux and gcc, tty.h will not compile if
       you don't define _LOOSE_KERNEL_NAMES.  It's a bug somewhere.
    */
#include <linux/tty.h>      /* console_print() interface */

/* Initialize the LKM */
int init_module()
{
  console_print("Hello, world - this is the kernel speaking\n");
  /* More normal is printk(), but there's less that can go wrong with 
     console_print(), so let's start simple.
  */

  /* If we return a non zero value, it means that 
   * init_module failed and the LKM can't be loaded 
   */
  return 0;
}


/* Cleanup - undo whatever init_module did */
void cleanup_module()
{
  console_print("Short is the life of an LKM\n");
}

i compile the program using the command:
gcc -c hello.c -Wall

When i compile the program i get the following errors:
/usr/include/linux/modversions.h:1:2: #error Modules should never use kernel-headers system headers,
/usr/include/linux/modversions.h:2:2: #error but rather headers from an appropriate kernel-source package.
/usr/include/linux/modversions.h:3:2: #error Change -I/usr/src/linux/include (or similar) to
/usr/include/linux/modversions.h:4:2: #error -I/lib/modules/$(uname -r)/build/include
/usr/include/linux/modversions.h:5:2: #error to build against the currently-running kernel.

Appreciate the help.
thanks,
Preetham.

added code tags for readability --oombera