Comments (3)
I know that at least bash caches executables on $PATH , most likely for exactly this reason.
from oil.
Yeah I just checked bash and dash. The first time they stat()
everything on PATH. Then the second time they know where it is.
I will have to research the cache invalidation though. It seems like there are 2 cases:
-
$PATH is changed. Technically you don't have to invalidate the whole cache, if the cache lists all of
/bin
/usr/bin/
etc. and some of them are still on $PATH. -
If any directory in
$PATH
changes (new programs can be inserted there). Before using the cache I think you have to check the timestamp on the directory to make sure it hasn't changed.
$ PATH=/bin:/usr/bin:_tmp/1 strace -e stat,execve -ff -- dash -c 'prog; prog'
execve("/bin/dash", ["dash", "-c", "prog; prog"], [/* 74 vars */]) = 0
stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/bin/prog", 0x7fff2c3fedc0) = -1 ENOENT (No such file or directory)
stat("/usr/bin/prog", 0x7fff2c3fedc0) = -1 ENOENT (No such file or directory)
stat("_tmp/1/prog", {st_mode=S_IFREG|0775, st_size=7, ...}) = 0
strace: Process 27141 attached
[pid 27141] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27141] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27141] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27141] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27141] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27141, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 27142 attached
[pid 27142] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27142] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27142] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27142] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27142] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27142, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++
dash does the same thing as bash AFAICT:
andy@lisa:~/git/alpine/abuild$ PATH=/bin:/usr/bin:_tmp/1 strace -e stat,execve -ff -- dash -c 'prog; prog'
execve("/bin/dash", ["dash", "-c", "prog; prog"], [/* 74 vars */]) = 0
stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/bin/prog", 0x7fff1eca4590) = -1 ENOENT (No such file or directory)
stat("/usr/bin/prog", 0x7fff1eca4590) = -1 ENOENT (No such file or directory)
stat("_tmp/1/prog", {st_mode=S_IFREG|0775, st_size=7, ...}) = 0
strace: Process 27152 attached
[pid 27152] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27152] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27152] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27152] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27152] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27152, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 27153 attached
[pid 27153] execve("_tmp/1/prog", ["prog"], [/* 74 vars */]) = -1 ENOEXEC (Exec format error)
[pid 27153] execve("/bin/sh", ["/bin/sh", "_tmp/1/prog"], [/* 74 vars */]) = 0
[pid 27153] stat("/home/andy/git/alpine/abuild", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
[pid 27153] stat(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
1
[pid 27153] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27153, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++
from oil.
Released with 0.7.pre1: https://www.oilshell.org/release/0.7.pre1/
from oil.
Related Issues (20)
- SIGINT and SIGTSTP breaks out of loops in bash/zsh, but not OSH HOT 6
- Implement shopt -s autocd HOT 3
- Error message shows wrong/confusing position for long commands HOT 3
- command -v "$emptyvar" returns zero HOT 3
- Oils 0.23.0 TODO
- Missing "Str=>lower()"
- Abort with += on missing dict key
- intermittent crash running amd-test script -- reproducible in dbg, opt HOT 4
- OpenBSD doesn't have RLIMIT_AS
- Add pp [x + 42] to print an expression and its value - like Rust dbg!() HOT 2
- github URL pastebin HOT 8
- bash allows pasting multi-line code snippets, but OSH/YSH don't HOT 3
- allow backspace from multiline expressions HOT 1
- allow any custom prompts HOT 2
- typeof / reflection / assign results of '=' HOT 3
- emoji/unicode identifiers
- Setting up GNU readline history HOT 1
- 'view latest' released version in documentation - because old links are often surfaced HOT 1
- crash in parsing return HOT 1
- BashArray could have a sparse representation (ble.sh)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oil.