Professional Documents
Culture Documents
Pstree Showing Name of Script
Pstree Showing Name of Script
http://unix.stackexchange.com/questions/32341...
sign up
log in
tour
Sign up
help
Anybody can
answer
Why is pstree showing the name of my script instead of the name of the shell that is interpreting it?
I have written a simple shell script as follows:
#!/bin/bash
sleep 90
After running this shell I run pstree in a separate shell to see the process tree structure.
Here is what I see
-gnome-terminal-+-bash---sleepy.sh---sleep
Why is a shell script being represented as a process by pstree? The ps command correctly shows the command being executed as
10150
8771
0 08:13 pts/1
Here the process is bash and sleepy.sh is its argument (this makes sense to me). In my view a process has to be an Executable Linkable Format
binary (ELF). Bash is an ELF executable but a shell script is not and hence I think pstree should not be showing it as such?
/ shell
/ process
Arthur2e5
878
sshekhar1980
19
16
1 Answer
pstree retrieves the process name from /proc/<pid>/stat . This is whatever was given to the
kernel via execve(2) 's first parameter; see proc(5) and What exactly happens when I execute
a file in my shell? for details. You'll see from the latter that the kernel can run shell scripts directly
(and many other "binaries" see How is Mono magical?), but the shell also steps in in some
cases.
with a shebang line at the start of the script, you'll see sleepy.sh in pstree 's output because
that's what the shell asks the kernel to run. If instead you run
sh ./sleepy.sh
1 of 2
11/16/2016 04:53 AM
http://unix.stackexchange.com/questions/32341...
Stephen Kitt
46.8k
2 of 2
74
102
11/16/2016 04:53 AM