hi,
i have a script.sh on my machine and it used in the system
but my question is how can i know the program called this script.sh??
i.e. from where it called and execute??
Many thanks
hi,
i have a script.sh on my machine and it used in the system
but my question is how can i know the program called this script.sh??
i.e. from where it called and execute??
Many thanks
You want to know which program invoked script.sh? A ps listing will reveal the parent PID. It's possible for the parent to exit before the child does, though; then your process will show as orphaned.
ps wallx | { head -1; grep 'script\.sh'; }
ps options vary wildly between systems; see your local manual page for what will work for you.
The head is just to get the explanatory header as well; in a script, you don't want that.
Example:
vbvntv$ ps wallx | { head -1; grep to*tem ; }
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
0 1000 9478 1 15 0 113136 30536 - SLl ? 32:30 totem
Here, the parent's PID (PPID) is 1, which is typical for an orphan (the system's init process adopts any orphans).