Hi !
>I need to change behavior of shell script(s) if they get invoked from a
>main shell, that is a shell (interactive or not) which is a direct
>child of process #1 (init). How to determine if script has been invoked
>in this environment? What is the best/easiest solution for this?
I have spend some hour thinking about it I've come up with a solution
for my question:
#!/bin/busybox sh
IFS=" " read xxx xxx xxx m_ppid xxx m_sid xxx </proc/$$/stat \
&& IFS=" " read xxx xxx xxx p_ppid xxx p_sid xxx </proc/$PPID/stat \
&& echo "pid=$$, ppid=$m_ppid, gid=$m_gid, sid=$m_sid" \
&& echo "pid=$PPID, ppid=$p_ppid, gid=$p_gid, sid=$p_sid" \
|| { echo failed; exit 1; }
if [ "$m_ppid" == "$PPID" -a "$m_sid" == "$PPID" \
-a "$p_sid" == "$PPID" -a "$p_ppid" == "1" ]
then echo "invoked from top level shell"
else echo "not invoked from top level shell"
fi
exit 0
This assumes invocation from top level shell if own parent process id
matches own session id AND parent process is the session leader AND
parent of session leader is process 1.
It looks not so bad in my eyes ... but in case: Is there an easier way?
Any other suggestions?
Thx for your contribution (-> pure none commercial usage ).
Harald
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox