When I programmerly do open -F -W -n -g -a /Applications/Safari.app/Contents/MacOS/Safari https://kernel.org
, I got back the process of open
and its pid 93930.
But that's not the process (93931) of newly created Safari instance itself.
huocp 93931 0.0 1.9 6047904 160240 ?? S 11:55am 0:04.39 /Applications/Safari.app/Contents/MacOS/Safari
huocp 93930 0.0 0.1 4340272 12212 s004 S+ 11:55am 0:00.07 open -F -W -n -g -a /Applications/Safari.app/Contents/MacOS/Safari https://kernel.org
Now I have no way to close the Safari process programmerly. I can close the open
process programmerly by killing 93930, but it leaves 93931 running.
So the question is: is there a way to get the pid of the application instance created by open
command?
93931 (safari) is not even a child process of 93930 (open), I tried with pstree command.
open -FWnga Safari https://kernel.org
does the same thing as the command you've shown, no need to draw it out the way you have. If you're looking to close the last opened occurrence of Safari, then this will do it:kill -nx Safari
However, the next time you use the aforementionedopen
command, the-F
option will be ignored. In other words, the next time there will be two tabs forhttps://kernel.org
.-nx
, but pgrep does the trick.pkill -nx Safari
will do it.kill
was a typo on my part, which I missed when copying it from Terminal after testing.