Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Hi I have a server which can communicate with clients using TCP protocol. The server may crash anytime, so I need to restart my server automatically, How can I do that?
A watchdog timer? Do you mean have it automatically reboot at specific intervals, auto-reboot after a crash, or send you an automatic email so you can reboot it?
I want may be another process look for my server in process list whether it is running or not if it doesn't run then the Monitor process will restart my server. but my problem is that if I restart the process with exec of C then the server can't communicate through the port.
You can make a shell script. The algo may look like this.
while(1)
{
if(!pgrep <Your process name>)
restart your server
sleep <amount of seconds you should wait to recheck>
}
put the script in your rc.local file.
I hope somebody with good scripting knowledge will provide a better ans.
Another alternative is to use cron as the timing mechanism instead of writing a daemon, otherwise that script (post 4) will do an infinite loop and the system won't start.
If you want to write a daemon, use
I want may be another process look for my server in process list whether it is running or not if it doesn't run then the Monitor process will restart my server. but my problem is that if I restart the process with exec of C then the server can't communicate through the port.
So plz if u have any suggestion let me know.
And what is the error when you try to restart?
If it's a program that you wrote yourself, it's more advisable to have a look why the program crashes and fix it. If it's a program that's written by someone else, inform him/her so it can be fixed.
thanks chrism01 I have solved my problem using script.
But now my problem is after executing the script that contains
nohup yourdaemon >/somedir/yourdaemon.log 2>&1 & command when I use top command it shows that my server.exe takes always 100% cpu in a dual core machine.
and when I use the kill pid command it can't kill the process.
Well, it's getting started by root if its in rc.local, so you'd have to be root to stop it.
If you look at top, it'll show you who owns the process.
The 100% cpu usage is down to your code, you'll have to debug it.
My cmd just starts it in the background (final &) and detaches from the terminal/current process (nohup).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.