Thanks, I'll check it out. Il giorno dom 8 gen 2023 alle 05:29 Jim ha scritto: > > On Sat, Jan 7, 2023 at 11:23 AM Pier Paolo Grassi > wrote: > >> Thanks, but i don't _always_ redirect stdin. >> i wonder how is ps getting the tty (it displays an ? when there is no tty >> for the process) >> I suppose it uses /proc, but couldn't find a reference or the info >> exploring the /proc fs by myself. >> for now I am asking directly ps: >> [[ "$(ps h -o tty $$)" != "?" ]] && ... >> >> Pier Paolo Grassi >> >> Hi, > > Don't really have an answer how ps gets its info but the attached script > is something > I have been working on. It uses the /proc file system directly to get > info. It uses zstat > to look for the tty info. If nothing is returned it substitutes '?". > Some processes point to > /dev/null. The script is still a work in progress. I was trying to get the > same results as > "ps -eHo uid=,pid=,ppid=,tty=,comm=" via a zsh script. > > This doesn't answer your original question, but may give you some insight > into the > /proc file system. > > Hope the script is helpful. > > Regards, > > Jim Murphy > > -- Pier Paolo Grassi