www.pudn.com > closeonexec.rar > usefd.cpp
// This program is written by Li,Suke. // School of Software and Microelectronics, // Beijing University. // I hope this program can be useful. // September 11, 2006 #include#include #include using namespace std; int main(int argc, char *argv[]) { const char *msg = " This is from usedfd. "; if (argc != 2) { cout << "Usage usefd " << endl; exit(1); } int fd = atoi(argv[1]); cout << "usefd:The file descriptor from usefd is " << fd << endl; if (fd > 0) { int n = write(fd, msg, strlen(msg)); if (n < 0) { perror("write"); exit(1); } } return 0; }