[Top][All Lists]

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

BUG: "time" command adding to wrong process.

From: James Bonfield
Subject: BUG: "time" command adding to wrong process.
Date: Wed, 08 Jan 2014 12:00:54 +0000

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 -Wall
uname output: Linux deskpro102485 2.6.32-41-generic-pae #94-Ubuntu SMP Fri Jul 
6 17:08:20 UTC 2012 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 4.1
Patch Level: 5
Release Status: release

        If I have a process running in the background that finishes
        while I have a foreground process being timed using the
        builtin time command, then the CPU time of the background task
        is erroneously added on to the foreground task. This does not
        happen if the background task ends after the foreground task.

        $ cat ~/tmp/loop.c
        int main(int argc, char **argv) {
            int i, j, x = 0;
            int N = atoi(argv[1]);
            int M = 1000000;
            for (i = 0; i < N; i++)
                for (j = 0; j < M; j++)
                    x += i*j;
            return 0;
        $ gcc -g ~/tmp/loop.c

        $ ./a.out 1000 & time ./a.out 1100
        [3] 14577
        [3]   Done                    ./a.out 1000
        real    0m2.512s
        user    0m4.772s
        sys     0m0.008s

        $ ./a.out 1200 & time ./a.out 1100
        [3] 14579
        real    0m2.528s
        user    0m2.520s
        sys     0m0.000s

        Using a subshell avoids the problem:

        $ ./a.out 1000 & (time ./a.out 1100)
        [3] 14589
        real    0m2.548s
        user    0m2.536s
        sys     0m0.000s
        [3]   Done                    ./a.out 1000

        $ (./a.out 1000 &); time ./a.out 1100
        real    0m2.502s
        user    0m2.492s
        sys     0m0.004s

        Is this an issue with process groups?

 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 

reply via email to

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