Results 1 to 6 of 6

Thread: Infinite loop in bash

  1. #1
    Join Date
    Mar 2010
    Posts
    222

    Infinite loop in bash

    Hello,
    I would like to make a loop in bash to Re-starter a program when it crashes. But I do not have any idea of programming in linux. I need to create a small program that can help one customize my desktop. How can I do this. Any help is appreciated. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    Re: Infinite loop in bash

    Hello,
    You can try the following program
    Code:
    / bin / bash
    
    while true;do
        pgrep temp> / dev / null 2> & 1
        if [ "$?" != "0" ];then
    	temp &
        fi
        sleep 2
    done
    I hope this has helped you. I recommend you to take some basic tutorials on this topic.

  3. #3
    Join Date
    Dec 2009
    Posts
    211

    Re: Infinite loop in bash

    Hello,
    Checks in a console when the server binary is launched, the command
    Code:
    pgrep methodnm()
    returns something, otherwise it is normal that the script does not work. If you are using this in your code then you have to take care of the errors which you will come through, if not then you will face problems in future.

  4. #4
    Join Date
    Nov 2009
    Posts
    330

    Re: Infinite loop in bash

    Hello,
    You can try the following bash code, I think that will help you.
    Code:
    while :; do
            . / trinity-core
            sleep 1
    done
    But I think when you will try to crash the server, I am not sure that this will work perfectly. Just have a try at it and if you have nay more problem then do post back with your errors.

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Infinite loop in bash

    Hello,
    I think this is the one which you are looking for, take a look at the bash script below and also if it has helped you then post back.
    Code:
    / bin / bash
    
    while true;do
        pgrep temp > / dev / null 2> & 1
        if [ "$?" != "0" ];then
    	. / temp &
        fi
        sleep 2
    done

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Infinite loop in bash

    Hello,
    I'm not quite sure I understand, your request "I want to loop in bash to Restarter a program when it crash. While "When a program crash, it continues execution." This is exactly what this script is, if there is no trinity-core process started, it launches, if it attempts two seconds before checking again.
    Make a simple code
    Code: C + +
    Code:
    while true;do
        ./trinity-core
    done

Similar Threads

  1. Infinite Loop Fix moniter issue
    By Romany in forum Monitor & Video Cards
    Replies: 5
    Last Post: 02-04-2010, 10:39 AM
  2. Facebook Infinite Loop after Login
    By Chitamacha in forum Technology & Internet
    Replies: 5
    Last Post: 02-04-2010, 10:04 AM
  3. Is it possible to terminate an infinite loop?
    By Sheru in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 02:09 PM
  4. Problem of infinite loop in C
    By Firon in forum Software Development
    Replies: 4
    Last Post: 11-05-2009, 06:12 PM
  5. nv4_disp infinite loop error
    By Khushal in forum Hardware Peripherals
    Replies: 2
    Last Post: 29-07-2008, 02:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,926,849.25805 seconds with 16 queries