I am reading a complex book on Linux that introduced the /proc/self directory. Please bare in mind that I come from a heavy Windows background, so this is all really new to me. Now, In an attempt to find more information on this directory, I read on an Oracle blog
that stated the following command
ls -l /proc/self
may output the following
lrwxrwxrwx 1 root root 64 Jan 6 13:22 /proc/self -> 13833
Where process 13833 is that of ls -l; hence, the directory /proc/13883 will have existed but only for the duration of the call to ls -l was running. I understand this, but what I don't quite get is what is happening when I type cd /proc/self: what process is this?
1) Is it my current bash shell?
I assumed that this was the case, so was trying to find a way to change one of the file descriptors currently open:
[Me@OLE6 fd]$ cd /proc/self/fd
[Me@OLE6 fd]$ ls -l
lr-x------. 1 Me Me 64 Mar 23 19:10 0 -> /dev/pts/0
lrwx------. 1 Me Me 64 Mar 23 19:10 1 -> /dev/pts/0
lrwx------. 1 Me Me 64 Mar 23 19:10 2 -> /dev/pts/0
lrwx------. 1 Me Me 64 Mar 23 19:24 255 -> /dev/pts/0
I figured if I could redirect stdin, stdout, stderr in my bash shell, to something else, then I could check back in this directory and expect to see the output from the above command change - then I would know that /proc/self is the current bash shell.
However, I couldn't see how to do this. I tried 2>stderr.txt
in an attempt to redirect stderr but that had no effect. I also tried opening a second terminal and commanding 1>/dev/pts/1
, but that didn't work either (whereas a single string, like echo Hi>/dev/pts/1
did work as expected)
2) How can I redirect one of the three standard files to somewhere else?
3) What is FD 255 in the output I showed above?