
unix编程
cozzw
这个作者很懒,什么都没留下…
展开
-
读取用户信息
获取用户信息 #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 · 382 阅读 · 0 评论 -
消息队列
消息队列:先进先出根据不同的交易类型组建不同的消息报文,填写不同的消息类型,写入同一消息队列。各类交易处理程序分别从消息队列中读取特定类型的消息并处理(即使不在队头,读完后从队列中删除)发送端:#include #include #include using namespace std;extern int errno;struct Msg{lo原创 2013-03-18 17:45:21 · 445 阅读 · 0 评论 -
共享内存
共享内存:最快的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 · 652 阅读 · 0 评论 -
报文解析
操作文件: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 · 1207 阅读 · 0 评论 -
管道
单向无名管道:占用两个文件描述符(读,写),用于父子进程中父写子读#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 · 489 阅读 · 0 评论 -
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 · 490 阅读 · 0 评论 -
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 · 418 阅读 · 0 评论 -
记录锁
#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 · 534 阅读 · 0 评论 -
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 · 379 阅读 · 0 评论 -
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 · 385 阅读 · 0 评论 -
消息队列
消息队列,写进程#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 · 422 阅读 · 0 评论 -
获取系统信息
取得计算机名 #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 · 540 阅读 · 0 评论 -
进程
退出处理函数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 · 395 阅读 · 0 评论 -
文件操作
获取文件描述信息 #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 · 345 阅读 · 0 评论 -
获取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 · 304 阅读 · 0 评论 -
unix下目录操作
目录操作: 查看当前工作目录: #include using namespace std; int main() { char buf[256] = {}; size_t size; getcwd(buf, size); cout } 查看当前目录下的文件 #in原创 2013-03-04 19:42:59 · 322 阅读 · 0 评论 -
信号量
信号完成进程控制。同步:禁止生产者向满的缓冲区输送产品,禁止消费者向空的缓冲区提取产品;互斥:生产者向缓冲区输送产品时,禁止消费者进入,同理,消费者从缓冲区取走产品时,禁止生产者输送产品。信号量:一组整型变量,为控制临界资源而产生的一个或一组计数器;P操作申请资源,信号值减1;V操作释 放资源,信号量加1信号量控制:semctl(semid, semnu,原创 2013-03-18 17:46:42 · 440 阅读 · 0 评论