⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daemon.cc

📁 达内IT培训Unix C++第三天源码 是入门Unix 下C++编程的好东西
💻 CC
字号:
#include <iostream>using namespace std;#include <unistd.h>#include <fcntl.h>int main(){	if(fork()!=0){		cout << "parent exit." << endl;		return 0;	}	sleep(2);	cout << "now my pid:" << getpid() << ", my parent id:" << getppid() << endl;	setsid();	for(int i=0; i<3; i++)		close(i);	//其他准备工作....	char ch='A';	for(;;){//服务工作		int fd=open("letter",O_WRONLY|O_CREAT, 0644);		if(fd>=0){			write(fd, &ch, 1);			sleep(2);			if(++ch>'Z')				ch = 'A';			close(fd);		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -