Execute all processes in the background from bash.

Ask a Question related to Linux / Unix Administration, Design and Development.

  1. #1

    Default Execute all processes in the background from bash.

    I was wondering if it's possible to prepend "time" and append "&" to all
    commands that I execute in bash. For example I'd like
    $ mozilla
    to exapand to
    $ time mozilla &
    to time it and execute it in the background. Anyone know if this is
    possible using bash, maybe with environment variables? It's quite
    inconvenient to type time before and & after every command that I execute.
    Thank you.

    * Anthony
    guerrilla_thought Guest

  2. Similar Questions and Discussions

    1. problem using bash variables with command-line perl in bash script
      Hi! I have a problem with variables when using command-line perl in a bash script. The script should update a date (in 2003-10-10 form) if the...
    2. running background (daemon) processes in Windows
      In Unix I can start a 'deamon' (background) process like: ruby -e 'fork do system("something") end' Or by putting the fork directly into my...
    3. Background processes inside the database.
      I am looking for a way to have a session spawn a background process and release. The user needs to be able to start a job which could conceivably...
    4. How to execute perl from bash
      Hi everyone! I need to trip blank spaces at begin and end on certain string. I can do it executing perl -e '$str = " 2003-07-29 "; $str =~...
    5. Oracle background processes
      gotta_know wrote: Not if you go through the trouble to make it work. Though anything you have written that deals with file permissions, etc....
  3. #2

    Default Re: Execute all processes in the background from bash.

    On Wed, 19 May 2004 08:33:06 GMT, guerrilla_thought <guerrilla_thought@gmx.de> wrote:
    >
    >
    > I was wondering if it's possible to prepend "time" and append "&" to all
    > commands that I execute in bash. For example I'd like
    > $ mozilla
    > to exapand to
    > $ time mozilla &
    > to time it and execute it in the background. Anyone know if this is
    > possible using bash, maybe with environment variables? It's quite
    > inconvenient to type time before and & after every command that I execute.
    > Thank you.
    >
    > * Anthony
    One way would be to use the PROMPT_COMMAND Bash variable to run a function
    just before the prompt came up:

    function_name () {

    read PC

    time "${PC}" &

    }

    Doesn't really run in the background, though, and I can't make common
    commands run in the background at all. Try ls & ...

    Of course, that function takes away your prompt, so you need to
    include one in the function...

    Hang around. There are probably better ideas coming along...


    AC

    --
    Pass-List -----> Block-List ----> Challenge-Response
    The key to taking control of your mailbox. Design Parameters:
    [url]http://tinyurl.com/2t5kp[/url] || [url]http://tinyurl.com/3c3ag[/url]
    Challenge-Response links -- [url]http://tinyurl.com/yrfjb[/url]
    Alan Connor Guest

  4. #3

    Default Re: Execute all processes in the background from bash.


    On Wed, 19 May 2004, guerrilla_thought wrote:
    > I was wondering if it's possible to prepend "time" and append "&" to all
    > commands that I execute in bash. For example I'd like
    > $ mozilla
    > to exapand to
    > $ time mozilla &
    > to time it and execute it in the background. Anyone know if this is
    > possible using bash, maybe with environment variables? It's quite
    > inconvenient to type time before and & after every command that I execute.
    > Thank you.
    >
    If your bash is using GNU-readline for obtaining user input (it probably
    does), then you could add something similar to the following into your
    ~/.inputrc:

    '\C-a': beginning-of-line
    '\C-e': end-of-line
    '\C-n': accept-line
    '\C-m': "\C-a time \C-e &\C-n"

    See the readline man page for more details.


    Regards,

    Timo Felbinger


    --
    Timo Felbinger <Timo.Felbinger@physik.uni-potsdam.de>
    Quantum Physics Group [url]http://www.quantum.physik.uni-potsdam.de[/url]
    Institut fuer Physik Tel: +49 331 977 1793 Fax: -1767
    Universitaet Potsdam, Germany
    Timo Felbinger Guest

  5. #4

    Default Re: Execute all processes in the background from bash.

    guerrilla_thought wrote:
    >
    > I was wondering if it's possible to prepend "time" and append "&" to all
    > commands that I execute in bash. For example I'd like
    > $ mozilla
    > to exapand to
    > $ time mozilla &
    > to time it and execute it in the background. Anyone know if this is
    > possible using bash, maybe with environment variables? It's quite
    > inconvenient to type time before and & after every command that I execute.
    All/every? I use ls, cd and so on often enough that would be a
    disaster for me.

    When I intend to run a command very often, I write a small script
    and name it "x" somewhere in my path. It would be something like:

    #! /bin/bash
    time ${1} &
    exit

    Then I would type most of my commands normally and "x mozilla".
    Since you mentioned mozilla, you probably want to use "nohup" rather
    than "time".
    Doug Freyburger Guest

  6. #5

    Default Re: Execute all processes in the background from bash.



    Doug Freyburger wrote:

    <snip>
    > All/every? I use ls, cd and so on often enough that would be a
    > disaster for me.
    >
    > When I intend to run a command very often, I write a small script
    > and name it "x" somewhere in my path. It would be something like:
    >
    > #! /bin/bash
    > time ${1} &
    You might want to make the above:

    time "$@" &

    so you capture arguments.
    > exit
    No need for the exit.

    Ed.
    >
    > Then I would type most of my commands normally and "x mozilla".
    > Since you mentioned mozilla, you probably want to use "nohup" rather
    > than "time".
    Ed Morton Guest

  7. #6

    Default Re: Execute all processes in the background from bash.

    Ed Morton wrote:
    > Doug Freyburger wrote:
    >
    > > When I intend to run a command very often, I write a small script
    > > and name it "x" somewhere in my path. It would be something like:
    >
    > > #! /bin/bash
    > > time ${1} &
    >
    > You might want to make the above:
    > time "$@" &
    > so you capture arguments.
    Good point.
    > > exit
    >
    > No need for the exit.
    True but there isn't necessarily need for the magic number in the first
    line, either. I put them into all of my scripts for cleanliness reasons.
    Doug Freyburger Guest

  8. #7

    Default Re: Execute all processes in the background from bash.

    In article <7960d3ee.0405200757.2b49b50f@posting.google.com >, Doug Freyburger
    wrote:
    > Ed Morton wrote:
    >> Doug Freyburger wrote:
    >>
    >> > When I intend to run a command very often, I write a small script
    >> > and name it "x" somewhere in my path. It would be something like:
    >>
    >> > #! /bin/bash
    >> > time ${1} &
    >>
    >> You might want to make the above:
    >> time "$@" &
    >> so you capture arguments.
    >
    > Good point.
    >
    >> > exit
    >>
    >> No need for the exit.
    >
    > True but there isn't necessarily need for the magic number in the first
    > line, either. I put them into all of my scripts for cleanliness reasons.
    I assume you mean the "shebang" entry (#!/bin/bash)? If so, there is a need for
    it, unless you want all your scripts to run as /bin/sh, which you probably
    don't. :)

    Kevin
    Kevin Collins Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139