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

Re: /usr/bin/env



> Marc Feeley <feeley@xxxxxxxxxxxxxxxx> writes:
> >    #! /usr/bin/env script-interpreter
> 
> > Anybody have experience, or comments about this?  Is /usr/bin/env
> > "standard" or POSIX?
> 
> from the Solaris 2.6 man page:
> 
>  /usr/bin/env
>      If env executes commands with arguments, it uses the default
>      shell /usr/bin/sh (see sh(1)).
> 
> So arguably more graceful looking than the traditional shell
> trampoline, but effectively the same thing...

I just measured the run time for the following three script
structures:

script s1:
            #! /u/feeley/gambc40a5/gsi/gsi
            (exit)

script s2:
            #! /bin/sh
            "exec" "gsi" "$0" "$@"
            (exit)

script s3:
            #! /usr/bin/env gsi
            (exit)

using Gambit on a RH Linux 1 GHz Athlon system (results of "time"
below).  It seems that the /usr/bin/env approach is just as fast as
specifying the absolute path of the interpreter (about 0.01 second to
start and exit the interpreter compared to about 0.05 second when
using /bin/sh).  So perhaps the use of /bin/sh by /usr/bin/env is
specific to Solaris (or maybe just non Linux systems).

Marc


% time ./s1 # 5 times
0.000u 0.010s 0:00.01 100.0%    0+0k 0+0io 451pf+0w
0.000u 0.010s 0:00.01 100.0%    0+0k 0+0io 451pf+0w
0.010u 0.000s 0:00.01 100.0%    0+0k 0+0io 451pf+0w
0.000u 0.010s 0:00.01 100.0%    0+0k 0+0io 451pf+0w
0.010u 0.000s 0:00.01 100.0%    0+0k 0+0io 451pf+0w
% time ./s2 # 5 times
0.000u 0.030s 0:00.07 42.8%     0+0k 0+0io 659pf+0w
0.000u 0.010s 0:00.05 20.0%     0+0k 0+0io 659pf+0w
0.020u 0.000s 0:00.05 40.0%     0+0k 0+0io 659pf+0w
0.000u 0.020s 0:00.05 40.0%     0+0k 0+0io 659pf+0w
0.010u 0.010s 0:00.05 40.0%     0+0k 0+0io 659pf+0w
% time ./s3 # 5 times
0.000u 0.020s 0:00.01 200.0%    0+0k 0+0io 556pf+0w
0.000u 0.010s 0:00.01 100.0%    0+0k 0+0io 556pf+0w
0.010u 0.000s 0:00.01 100.0%    0+0k 0+0io 556pf+0w
0.010u 0.000s 0:00.01 100.0%    0+0k 0+0io 556pf+0w
0.000u 0.010s 0:00.01 100.0%    0+0k 0+0io 556pf+0w