c++ - What do /proc/fd file descriptors show? -



c++ - What do /proc/fd file descriptors show? -

learning /proc/ directory today, in particular i'm interested in security implications of having info process semi-publicly available, wrote simple programme simple whatnot allows me explore properties of /proc/ directory:

#include <iostream> #include <unistd.h> #include <fcntl.h> using namespace std; extern char** environ; void is_linux() { #ifdef __linux cout << "this running on linux" << endl; #endif } int main(int argc, char* argv[]) { is_linux(); cout << "hello world" << endl; int fd = open("afile.txt", o_rdonly | o_creat, 0600); cout << "afile.txt open on: " << fd << endl; cout << "current pid: " << getpid() << endl;; cout << "launch arguments: " << endl; (int index = 0; index != argc; ++index) { cout << argv[index] << endl; } cout << "program environment: " << endl; (char** entry = environ; *entry; ++entry) { cout << *entry << endl; } pause(); }

interestingly though (to me anyway), when check file-descriptors folder (/pid/<pid#>/fd), see this:

root@excalibur-virtualbox:/proc/1546/fd# ls -l total 0 lrwx------ 1 root root 64 nov 7 09:12 0 -> /dev/null lrwx------ 1 root root 64 nov 7 09:12 1 -> /dev/null lrwx------ 1 root root 64 nov 7 09:12 2 -> /dev/null lrwx------ 1 root root 64 nov 7 09:12 3 -> socket:[11050]

why file descriptors point /dev/null? prevent user's beingness able inject content file without beingness process itself, or off base of operations on that? , more curious, why file descriptor open file point socket? seems odd. if can shed lite on me, appreciate it. thanks!

you looking @ wrong /proc directory (for other pid or on computer). contents of /proc/<pid>/fd programme should here:

lrwx------ 1 user grouping 64 nov 7 22:15 0 -> /dev/pts/4 lrwx------ 1 user grouping 64 nov 7 22:15 1 -> /dev/pts/4 lrwx------ 1 user grouping 64 nov 7 22:15 2 -> /dev/pts/4 lr-x------ 1 user grouping 64 nov 7 22:15 3 -> /tmp/afile.txt

here can see file descriptors 0, 1, , 2 shown symbolic links pseudo terminal in programme running. /dev/null if started programme input, output, , error redirection. file descriptor #3 points file afile.txt opened.

c++ linux posix

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -