CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FileDescriptorHandler.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <sstream>
5 
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <dirent.h>
9 
10 #include <stdlib.h>
11 
12 
13 namespace evf{
14 
16 
17  //find all socket file descriptors inherited from parent process and close them
18 
19  pid_t pid = ::getpid();
20  std::ostringstream ost;
21  ost << "/proc/" << pid << "/fd/";
22  DIR *dir = opendir(ost.str().c_str());
23  dirent *de;
24  struct stat buf;
25  while((de = readdir(dir))!=0){
26  char *name = de->d_name;
27  std::string path = ost.str()+name;
28  stat(path.c_str(),&buf);
29  if(S_ISSOCK(buf.st_mode)){
30  int fd = atoi(name);
31  close(fd);
32  }
33  }
34  closedir(dir);
35 }
36 
37 }
int path() const
Definition: HLTadd.h:3
list DIR
Definition: linker.py:124
dbl *** dir
Definition: mlp_gen.cc:35