help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why does </proc/self/environ not work in bash?


From: Koichi Murase
Subject: Re: why does </proc/self/environ not work in bash?
Date: Mon, 12 Feb 2024 00:12:33 +0900

2024年2月11日(日) 23:17 Greg Wooledge <greg@wooledge.org>:
> But... wait, now I'm even more confused:
>
> unicorn:~$ ( sleep 3 & exec 3</proc/$!/environ ; cat <&3 )
> unicorn:~$
>
> How come *that* one didn't print anything?

I think the stream opened for /proc/xxx/environ is invalidated on exec
of the process of PID xxx. Then, the next question is why
/proc/xxx/comm and /proc/xxx/cmdline are not invalidated on exec of
the process. I found an interesting behavior:

$ bash -c 'read -N 1;printf %s "$REPLY"; cat' < /proc/self/cmdline
bat

I'm on GNU/Linux. This might mean that the stream for
/proc/xxx/cmdline only remembers the offset and just accesses the
"current" memory block allocated for the command line when `read' is
requested.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]