help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Self terminating code for bash scripts


From: Chris Down
Subject: Re: [Help-bash] Self terminating code for bash scripts
Date: Tue, 19 Mar 2013 23:15:37 +0800

On 19 March 2013 22:56, adrelanos <address@hidden> wrote:
> When I am running a script, I wish, that it kills any previous instances
> of itself in case it is still running. How can I do that?

    pids=( $(pgrep "$0") )
    for pid in "address@hidden"; do
        [[ "$pid" != "$$" ]] && kill "$pid"
    done

Untested, it would be much better to just use a lock file anyway.

Chris



reply via email to

[Prev in Thread] Current Thread [Next in Thread]