Using lsof, I'm unable to get the PID of the file which gets updated using while loop.
┌─[stalin@testbox] - [/tmp] - [Mon Jan 11, 18:50]
└─[$]> sh hostname.sh&
[1] 75634
┌─[stalin@testbox] - [/tmp] - [Mon Jan 11, 18:50]
└─[$]> cat /tmp/hostname.txt
testbox
┌─[stalin@testbox] - [/tmp] - [Mon Jan 11, 18:50]
└─[$]> lsof /tmp/hostname.txt
┌─[stalin@testbox] - [/tmp] - [Mon Jan 11, 18:50]
└─[$]> cat hostname.sh
#!/bin/zsh
while sleep true; do echo $(hostname) > /tmp/hostname.txt; done
┌─[stalin@testbox] - [/tmp] - [Mon Jan 11, 18:50]
└─[$]> uname -a
Darwin testbox 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…