为啥相同的事情为何要操作两遍呢,更多的可能是为了兼容在*nix下都可以使用而不出问题。
- if ((pid = fork()) < 0)
- syslog(LOG_ALERT, "fork failed: %s", xstrerror());
- else if (pid > 0)
- exit(0);
- if (setsid() < 0)
- syslog(LOG_ALERT, "setsid failed: %s", xstrerror());
- #ifdef TIOCNOTTY
- if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
- ioctl(i, TIOCNOTTY, NULL);
- close(i);
- }
- #endif