Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.