LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-28-2004, 01:15 AM   #1
shilpig
LQ Newbie
 
Registered: May 2004
Posts: 8

Rep: Reputation: 0
How to start a program at bootup time?


I have added a line at end of /etc/rc.d/rc.local
/home/abc/hello start &

but still not able to see this ruuning at boot time. Checked this using ps-ef command. How can I start a program at bootup time?

My hello.c file is:
#include <stdio.h>

void main()
{
while(1)
{
printf("HELLO\n");
sleep(1);
}
}

I have compiled hello using commnd
cc -o hello hello.c


I have studied that:
The file /etc/rc.d/rc.local script is run by the init command at boot time, or when changing runlevels, after all other initialization is complete. You can use this file to add additional commands necessary for your environment. For instance, you can start additional daemons or initialize a printer.

Pls guide me..
 
Old 09-28-2004, 01:46 AM   #2
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
Look buddy first you have to check if there is a problem with your program that is not working or it is the rc.local that is not.
I think your program is initiated but sent to background as you have given the parameters "start &" so may be it runs somewhere in the background .
Anyway just modify your program. make it like

include <iostream.h0>

int main()
{
int a;
cout<<"Enter an integer = ";
cin>>a;
cout<<"The number is = "<<a;
return 0;
}

This will ask for input and must be noticed and do not send it to background. Just write this line in /etc/rc.d/rc.local
/home/abc/hello
do not initiate this program in background. Eleminate "start &" and try that.
Hope this will work.
 
Old 09-28-2004, 02:10 AM   #3
shilpig
LQ Newbie
 
Registered: May 2004
Posts: 8

Original Poster
Rep: Reputation: 0
I have tried ur sample code and found that that too is not working. So its certianly to do something with rc.local file and not my program hello.c / hello.cpp

I tried calling hello in foreground, /home/abc/hello as entry in rc.local but that doesnot work.

Any idea why?
 
Old 09-28-2004, 03:26 AM   #4
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
hi there

compile ur program and make a executable of that ,and then make a script
and put it in /etc/rc.d/init.d
u can call ur compild program the script

u can see some example scripts from there also to make ur own

then to make it start at boot time

chkconfig /etc/rc.d/init.d/<ur script name> on

regards
 
Old 09-28-2004, 04:46 AM   #5
shilpig
LQ Newbie
 
Registered: May 2004
Posts: 8

Original Poster
Rep: Reputation: 0
I am able to run my program by making a script called hellod in /etc/rc.d/init.d
The start portion of hellod contains daemon /usr/abc/hello

It works fine(with no display messages) if my hello program is

#include<stdio.h>
void main()
{
printf("HELLO 1\n");
sleep(40);
printf(" HELLO 2\n");
}
// here HELLO 1 and HELLO2 is not displayed on screen but the service waits for 4 seconds.

If modify my program to inifinte loop
#include<stdio.h>
void main()
{
while(1)
{
printf("HELLO 1\n");
sleep(40);
}
printf(" HELLO 2\n");
}
// here the system hangs on stsrting hellod service due to this infinite loop.

What should I do so that my program works in background and doesnot alter the startup procedure (in foreground). Actually I want to write a program to start polling on USB instead of this hello program. How will I do that?
 
Old 09-28-2004, 12:09 PM   #6
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
hi there

u should look for wrting a program for daemon

so , consult an networking book for that, Adv Programming in UNix Environmnt by W Richard Stevens is one book,there u can find the program for wrting a deamon,which can monitor and are free from the terminal

regards
 
Old 09-28-2004, 01:45 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
nohup <yourprog> &
will fire it off into the background and it will not terminate when rc.local does ie it will keep running.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
fsck delay reported bootup time? rmang Linux - General 2 10-30-2005 05:29 PM
How to make a program run at start up time. TruongAn Linux - Software 22 10-26-2005 06:50 PM
*LONG* bootup time Riallin Slackware 9 05-06-2005 02:55 PM
Linux kernel Bootup Time shrey_j Programming 0 10-16-2004 12:52 AM
Start a program at boot time cppkid Programming 3 08-31-2004 09:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration