Unix Technical Forum

How to start a Server prog written in C (using sockets) to start at bootup

This is a discussion on How to start a Server prog written in C (using sockets) to start at bootup within the Linux Operating System forums, part of the Unix Operating Systems category; --> How to start a Server prog written in C (using sockets) to start at bootup. I tried adding script ...


Go Back   Unix Technical Forum > Unix Operating Systems > Linux Operating System

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-18-2008, 06:33 PM
rajanyadav
 
Posts: n/a
Default How to start a Server prog written in C (using sockets) to start at bootup

How to start a Server prog written in C (using sockets) to start at
bootup. I tried adding script to rc5.d? But the problem is that since
the server starts listening on a port( 5000) the OS freezes and then I
have to bootup in rescue mode to remove that script.

All the script does is runs a program calle server written in C.

In the script I have followed the start, stop status pattern followed
in other rc5.d scripts.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-18-2008, 06:34 PM
Tauno Voipio
 
Posts: n/a
Default Re: How to start a Server prog written in C (using sockets) to startat bootup

rajanyadav wrote:
> How to start a Server prog written in C (using sockets) to start at
> bootup. I tried adding script to rc5.d? But the problem is that since
> the server starts listening on a port( 5000) the OS freezes and then I
> have to bootup in rescue mode to remove that script.
>
> All the script does is runs a program calle server written in C.
>
> In the script I have followed the start, stop status pattern followed
> in other rc5.d scripts.




The scripts in the rc directories are set up for controlling
C programs which are specifically written to run as daemons.

You cannot start a simple terminal-oriented program and
assume that it behaves as a proper daemon.

For details, get e.g. the book

W Richard Stevens, Advanced Programming in the UNIX
Environment

and read the chapter on daemons (and all others referred
from it).

--

Tauno Voipio
tauno voipio (at) iki fi
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 06:36 PM
rajanyadav
 
Posts: n/a
Default Re: How to start a Server prog written in C (using sockets) to start at bootup

I tried to make that program run as a daemon by using fork.
Lets say my server's name is server.
If I run it on terminal now I get the shell back and on doing ps -eaf
| grep ./server I can see the server is running
The I did this
Wrote a script called script.
I have attached it
Placed it in /etc/rc.d/init.c
cd /etc/rc5.d
ln -s /etc/rc.d/init.d/script S99script
ln -s /etc/rc.d/init.d/script K99script

Reboot

System hangs on blue screen before getting to login screen

Please advice what to do

Tauno Voipio wrote:
> rajanyadav wrote:
> > How to start a Server prog written in C (using sockets) to start at
> > bootup. I tried adding script to rc5.d? But the problem is that since
> > the server starts listening on a port( 5000) the OS freezes and then I
> > have to bootup in rescue mode to remove that script.
> >
> > All the script does is runs a program calle server written in C.
> >
> > In the script I have followed the start, stop status pattern followed
> > in other rc5.d scripts.

>
>
>
> The scripts in the rc directories are set up for controlling
> C programs which are specifically written to run as daemons.
>
> You cannot start a simple terminal-oriented program and
> assume that it behaves as a proper daemon.
>
> For details, get e.g. the book
>
> W Richard Stevens, Advanced Programming in the UNIX
> Environment
>
> and read the chapter on daemons (and all others referred
> from it).
>
> --
>
> Tauno Voipio
> tauno voipio (at) iki fi


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-18-2008, 06:36 PM
Tauno Voipio
 
Posts: n/a
Default Re: How to start a Server prog written in C (using sockets) to startat bootup

> Tauno Voipio wrote:
>
>>rajanyadav wrote:
>>
>>>How to start a Server prog written in C (using sockets) to start at
>>>bootup. I tried adding script to rc5.d? But the problem is that since
>>>the server starts listening on a port( 5000) the OS freezes and then I
>>>have to bootup in rescue mode to remove that script.
>>>
>>>All the script does is runs a program calle server written in C.
>>>
>>>In the script I have followed the start, stop status pattern followed
>>>in other rc5.d scripts.

>>
>>
>>
>>The scripts in the rc directories are set up for controlling
>>C programs which are specifically written to run as daemons.
>>
>>You cannot start a simple terminal-oriented program and
>>assume that it behaves as a proper daemon.
>>
>>For details, get e.g. the book
>>
>> W Richard Stevens, Advanced Programming in the UNIX
>> Environment
>>
>>and read the chapter on daemons (and all others referred
>>from it).
>>


(-- top-posting corrected - tv --)

rajanyadav wrote:
> I tried to make that program run as a daemon by using fork.
> Lets say my server's name is server.
> If I run it on terminal now I get the shell back and on doing ps -eaf
> | grep ./server I can see the server is running
> The I did this
> Wrote a script called script.
> I have attached it
> Placed it in /etc/rc.d/init.c
> cd /etc/rc5.d
> ln -s /etc/rc.d/init.d/script S99script
> ln -s /etc/rc.d/init.d/script K99script
>
> Reboot
>
> System hangs on blue screen before getting to login screen
>
> Please advice what to do
>


Please get the reference and READ IT. It's not sufficient to
place a process simply into background by a fork()- You need
to handle with the process group and console affinities as well.

(You could learn to use Google: I got about 6 million hits
by 'linux daemon programming').

--

Tauno Voipio
tauno voipio (at) iki fi
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 06:36 PM
The Natural Philosopher
 
Posts: n/a
Default Re: How to start a Server prog written in C (using sockets) to startat bootup

Tauno Voipio wrote:
>> Tauno Voipio wrote:
>>
>>> rajanyadav wrote:
>>>
>>>> How to start a Server prog written in C (using sockets) to start at
>>>> bootup. I tried adding script to rc5.d? But the problem is that since
>>>> the server starts listening on a port( 5000) the OS freezes and then I
>>>> have to bootup in rescue mode to remove that script.
>>>>
>>>> All the script does is runs a program calle server written in C.
>>>>
>>>> In the script I have followed the start, stop status pattern followed
>>>> in other rc5.d scripts.
>>>
>>>
>>>
>>> The scripts in the rc directories are set up for controlling
>>> C programs which are specifically written to run as daemons.
>>>
>>> You cannot start a simple terminal-oriented program and
>>> assume that it behaves as a proper daemon.
>>>
>>> For details, get e.g. the book
>>>
>>> W Richard Stevens, Advanced Programming in the UNIX
>>> Environment
>>>
>>> and read the chapter on daemons (and all others referred
>>> from it).
>>>

>
> (-- top-posting corrected - tv --)
>
> rajanyadav wrote:
> > I tried to make that program run as a daemon by using fork.
> > Lets say my server's name is server.
> > If I run it on terminal now I get the shell back and on doing ps -eaf
> > | grep ./server I can see the server is running
> > The I did this
> > Wrote a script called script.
> > I have attached it
> > Placed it in /etc/rc.d/init.c
> > cd /etc/rc5.d
> > ln -s /etc/rc.d/init.d/script S99script
> > ln -s /etc/rc.d/init.d/script K99script
> >
> > Reboot
> >
> > System hangs on blue screen before getting to login screen
> >
> > Please advice what to do
> >

>
> Please get the reference and READ IT. It's not sufficient to
> place a process simply into background by a fork()- You need
> to handle with the process group and console affinities as well.
>


Try looking at the source of a really simple daemon program. I can;t
think of one right now...but...

> (You could learn to use Google: I got about 6 million hits
> by 'linux daemon programming').
>


Mmm;-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-18-2008, 06:37 PM
Charlie Gibbs
 
Posts: n/a
Default Re: How to start a Server prog written in C (using sockets) to startat bootup

In article <1157669466.17773.3@proxy01.news.clara.net>, a@b.c
(The Natural Philosopher) writes:

> Try looking at the source of a really simple daemon program. I can;t
> think of one right now...but...


http://www.erlenstar.demon.co.uk/unix/faq_toc.html contains a
description of the steps required to make your program run as
a daemon. This is the reference I successfully used when I
needed to do it myself.

--
/~\ cgibbs@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:03 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com