c++ - Create additional file descriptor that writes to terminal -


is possible create (from shell/bash or within c++ program) additional file descriptor stdout/stderr? i.e. default should write output terminal , mix both outputs, if wanted redirect them selectively?

my use case mpi-parallel c++ program running in multiple-program-multiple-data (mpmd) mode, i.e. several unrelated functional entities running simultaneously using different data sets. achieve default, output gets send terminal, able redirect 1 or more of output streams e.g. file.

standard output , standard error have file descriptors of 1 , 2, respectively. when start program, file descriptors default inherited child process. thus, if open file descriptor (e.g. 3) before starting program, able use if special fd stdout or stderr. can open fd writing in bash:

exec 3>/some/file 

note, however, while shells propagate open file descriptors children, programs spawn other programs may have policies. example, nohup redirects standard fds not touch others. other programs, while unlikely, may close fds above 2.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -