bug-bash
[Top][All Lists]
Advanced

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

[feature request] setpgid and setsid builtins


From: Francis Montagnac
Subject: [feature request] setpgid and setsid builtins
Date: Tue, 16 Apr 2002 17:07:16 +0200

Hi all.

I would like to have setpgid and setsid as bash builtins.

This would for example:

1)  Permit to write proper system bash scripts for re-spawning daemons.

    Without having setsid as bash buitins one has to rely on the real
    executable to detach itself from the tty. 

    Ex:

    if [[ $- == *i* ]]; then
        # Interactive shell. 
        (
            # A subshell in case the current process is a session
            # group leader.

            setsid
            exec <the real executable> <some options>
        )
    else
        # Probably called by init itself or already in a safe way.
        # Don't change the session id.

        exec <the real executable> <some options>
    fi

2)  Permit to define proper watchdogs.

  Ex:

  exec_with_timeout () {
    # exec_with_timeout <timeout> <command> [<args>]

    # Try to execute <command> in no more than <timeout> seconds.

    local timeout=$1
    shift

    local pid dogpid status

    ( "$@" ) &
    pid=$!
    setpgid $pid $pid

    # Watchdog
    ( sleep $timeout; kill -$pid; sleep 5; kill -KILL -$pid ) &> /dev/null &
    dogpid=$!
    setpgid $dogpid $dogpid

    wait $pid
    status=$?
    kill -KILL -$dogpid &> /dev/null
    return $status
  }

I dont see how to do that with the current (2.05a) version of bash.

Comments?

Francis.Montagnac@sophia.inria.fr, Tel: (33) 04 92 38 79 11, Bur: E106
INRIA Sophia, 2004, rte des Lucioles, B.P.93 - 06902 Sophia Antipolis Cedex



reply via email to

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