I am running an app that calls script.sh and I would like to retrieve the invoking app's PID or name within that same script.sh. Ultimately, in my script.sh, I am trying to determine whether the app or Terminal was the invoker (in order to run different commands)
I've added this to my script.sh
ps -p $PPID -o ucomm= >> /Users/john/Desktop/log.txt 2>&1
It seems the app is using etc/launchd
to open my default shell (zsh
) to run the script and not waiting... I believe this is called a "zombie process"?
man ps
says
When printing using the command keyword, a process that has exited and has a parent that has not yet waited for the process (in other words, a zombie) is listed as “”, and a process which is blocked while trying to exit is listed as “”. If the arguments cannot be located (usually because it has not been set, as is the case of system processes and/or kernel threads) the command name is printed within square brackets. The process can change the arguments shown with setproctitle(3). Otherwise, ps makes an educated guess as to the file name and arguments given when the process was created by examining memory or the swap area. The method is inherently somewhat unreliable and in any event a process is entitled to destroy this information. The ucomm (accounting) keyword can, however, be depended on. If the arguments are unavailable or do not agree with the ucomm keyword, the value for the ucomm keyword is appended to the arguments in parentheses.
(Emphasis mine)
However I don't see "defunct" or, when using the flag ucomm
, anything listed as mentioned in the man page.
Is there another set of flags or options I can try with ps to get more information?