- 博客(23)
- 资源 (4)
- 问答 (1)
- 收藏
- 关注
原创 共享内存
共享内存:最快的IPC对象,不借助第三方,可被多个进程直接访问写共享内存wshm.cc#include #include using namespace std;#define VERIFY(a,b)\if(a)\{\coutexit(-1);\}\else\coutint main(int argc, char* argv[])
2013-03-18 17:48:31 608
原创 信号量
信号完成进程控制。同步:禁止生产者向满的缓冲区输送产品,禁止消费者向空的缓冲区提取产品;互斥:生产者向缓冲区输送产品时,禁止消费者进入,同理,消费者从缓冲区取走产品时,禁止生产者输送产品。信号量:一组整型变量,为控制临界资源而产生的一个或一组计数器;P操作申请资源,信号值减1;V操作释 放资源,信号量加1信号量控制:semctl(semid, semnu,
2013-03-18 17:46:42 398
原创 消息队列
消息队列:先进先出根据不同的交易类型组建不同的消息报文,填写不同的消息类型,写入同一消息队列。各类交易处理程序分别从消息队列中读取特定类型的消息并处理(即使不在队头,读完后从队列中删除)发送端:#include #include #include using namespace std;extern int errno;struct Msg{lo
2013-03-18 17:45:21 406
原创 报文解析
操作文件:c++ 标准文件编程库、低级文件编程库报文解析读取passwd中的用户名#include #include using namespace std;int main(){ int fd1 = open("/etc/passwd", O_RDONLY); if(fd1 {coutreturn -1;
2013-03-15 20:05:21 1162
原创 unix精确定时
#include #include #include using namespace std;int n=0;void timefunc(int sig){signal(SIGPROF, timeunc);cout}int main(){struct itimerval value;value.it_value.tv_sec=1;
2013-03-15 20:03:58 385
原创 I/O操作
操作设备文件操作连接到主机串口的外设(密码键盘)打开串口设备:int open(char* devname){int fd;if((fd = open(devname, O_RDWR)) {coutreturn -1;}if((ioctl(fd, TCGETA, &oldtty)) {coutclose(fd);reteurn -
2013-03-15 20:03:05 461
原创 记录锁
#include #include using namespace std;int main(int argc, char* argv[]){int fd = open("a.txt", O_RDWR|O_CREAT, 0777);if(fd{coutreturn -1;}struct flock arg;arg.l_type = F_RDL
2013-03-15 20:01:58 505
原创 unix网络编程之udp
#include #include #include using namespace std; int main(int argc, char* argv[]) {short port = 12345;if(argc > 1) port = atoi(argv[1]); int ss = socket(AF_INET,SO
2013-03-08 21:12:52 346
原创 unix网络编程之tcp
ipserver.cc: #include #include #include using namespace std; int main(int argc, char* argv[]) {int ss = socket(AF_INET, SOCK_STREAM, 0);if(ss { cout return -1;
2013-03-08 21:11:42 283
原创 消息队列
消息队列,写进程#include #include using namespace std;int main(int argc, char* argv[]){ if(argc == 1) {coutreturn 0; } int key = atoi(argv[1]); int qid = msgget(
2013-03-07 21:12:27 387
原创 管道
单向无名管道:占用两个文件描述符(读,写),用于父子进程中父写子读#include using namespace std;int main(){int fileds[2];char buf[256];pid_t pid;if(pipe(fileds) {coutexit(-1);}if((pid=fork())
2013-03-07 21:11:06 451
原创 unix 信号
中断信号,自定义信号 #include #include using namespace std; void func(int sig) {if(sig == SIGINT) coutelse if(sig == SIGUSR1) cout else if(sig == S
2013-03-07 21:09:16 351
原创 进程
退出处理函数class A{ public: A(){ cout}~A(){ cout}};void f(){ cout }A gobj;int main(){ A obj; atexit(f); cout exit(0); cout}
2013-03-06 18:04:20 365
原创 获取系统信息
取得计算机名 #include using namespace std; int main() { char name[256]={}; int res; res = gethostname(name, 256); if(res cout elsecout }
2013-03-06 18:01:24 513
原创 文件操作
获取文件描述信息 #include #include using namespace std; int main(int argc, char* argv[]) { char* name = NULL; name = argv[1]// 命令行传递文件名 struct stat s; stat(
2013-03-06 17:59:55 319
原创 unix下目录操作
目录操作: 查看当前工作目录: #include using namespace std; int main() { char buf[256] = {}; size_t size; getcwd(buf, size); cout } 查看当前目录下的文件 #in
2013-03-04 19:42:59 293
原创 读取用户信息
获取用户信息 #include using namespace std; int main() { cout cout } 获取用户信息函数 #include #include using namespace std; int main(int argc, char* argv[])//命令行参数传递
2013-03-04 19:41:28 345
原创 获取unix环境变量
声明:unix板块下代码参考《21天学通c++》、精通UNIX下c语言编程与项目实践获取所有环境变量内容 #include using namespace std; int main(int argc, char* argv[], char* env[]) {for(int i=0; env[i]!=NULL; ++i)//编程习惯:对于指针数组,如果不说
2013-03-04 19:37:55 271
原创 静态顺序表的实现
/*******************************************the headfile of static sequence list, which defines the class of static seqlistfilename: sta_seqlist.hcopyright: cozzwauthor: zzwcreated date: 201
2013-01-31 10:25:11 204
转载 利用栈将中缀表达式转换成后缀表达式
目的:将中缀表达式(即标准形式的表达式)转换为后缀式。例子:a+b*c+(d*e+f)*g转换成abc*+de*f+g*+ 转换原则:1.当读到一个操作数时,立即将它放到输出中。操作符则不立即输出,放入栈中。遇到左圆括号也推入栈中。2.如果遇到一个右括号,那么就将栈元素弹出,将符号写出直到遇到一个对应的左括号。但是这个左括号只被弹出,并不输出。3.在读到操作符时,如
2012-10-11 17:18:01 860 1
原创 大白菜傻瓜式u盘装机
第一步:制作u盘启动盘 1、下载大白菜u盘启动盘制作工具 2、安装此工具 3、打开这个自作工具,选择要制作的u盘,然后单击一键制成usb启动盘 4、下载系统镜像文件到该启动盘 至此,启动盘制作成功!第二步:设置bio
2012-10-08 15:37:10 1531
原创 String 类构造函数
String::String(const char *str){ if(NULL==str) { m_data = new char[1]; if(m_data==NULL) { cout break;
2012-10-03 07:07:26 649
原创 函数返回值系列之一返回指针类型的局部变量
char * getString(void) { char p[] = "hello world"; return p;}//p 中保存的是栈中内容hello world 的首地址,而随着函数调用的结束hello world 被清除,所以p中保存的是乱码,函数的返回值正是指向该乱码的指针void test4(v
2012-09-23 19:14:50 260
TA创建的收藏夹 TA关注的收藏夹
TA关注的人