Home > Archive > Unix Programming > August 2005 > what happens when i run ps command on shell prompt?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
what happens when i run ps command on shell prompt?
|
|
| rahul8143@gmail.com 2005-08-29, 7:56 am |
| hello,
I want to know what exactly happens when i type $ps -a on shell
prompt? Does it actually forks current environment and swithes to ps
command code? Executes and retuen to parent process that is shell
prompt?
regards,
rahul.
| |
| Måns Rullgård 2005-08-29, 7:01 pm |
| rahul8143@gmail.com writes:
> hello,
> I want to know what exactly happens when i type $ps -a on shell
> prompt? Does it actually forks current environment and swithes to ps
> command code? Executes and retuen to parent process that is shell
> prompt?
Try running "strace ps". That should tell you quite a lot about what
happens.
--
Måns Rullgård
mru@inprovide.com
| |
| Philippe Amarenco 2005-08-29, 7:01 pm |
| rahul8143@gmail.com writes:
> hello,
> I want to know what exactly happens when i type $ps -a on shell
> prompt? Does it actually forks current environment and swithes to ps
> command code? Executes and retuen to parent process that is shell
> prompt?
> regards,
> rahul.
>
when executing a command from the shell, it forks, then close/open
file descriptors for redirections and such, then it execve to the
given command so that the forked shell is replaced by the
command. the original shell calls waitpid to wait that the process
running the command finish execution, then it continues.
--
Philippe Amarenco, aka Phix
epita 2007 - LSE - EpX
"if new true friend not protected for explicit private union, break
case and try using this." -- Nathan Myers, longest c++ sentence.
| |
| Pascal Bourguignon 2005-08-29, 7:01 pm |
| Måns Rullgård <mru@inprovide.com> writes:
> rahul8143@gmail.com writes:
>
>
> Try running "strace ps". That should tell you quite a lot about what
> happens.
However, strace doesn't show the initial fork.
To know exactly what happens when you type ps to the shell, have a
look at the sources of the shell.
Also, you can strace the shell itself:
strace -f /bin/bash
Wait for the prompt. the dump will end with a read call. Type:
ps RET
and see what happens in the shell.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
|
|
|
|
|