随笔分类 - 操作系统学习笔记
摘要:Ubuntu 14.04 (其他版本可能适用)浏览网页慢的一个重要原因是DNS默认为:172.0.0.1 查看/etc/resolv.conf 会看到他使用的dns是 nameserver 127.0.1.1 操作过程:修改/etc/resolv.conf, 将nameserver 改为你...
阅读全文
摘要:如果服务端的程序关闭后,端口不能马上释放掉,需要等一会才能小时,在这之间再启动服务程序是起不来的,但是可以用这个函数,边面这种情况,服务程序关闭后,可以马上再起一次,不会冲突了。listenfd = socket(AF_INET, SOCK_STREAM, 0);/* Enable addres...
阅读全文
摘要:【实验目的】掌握并灵活使用线程机制掌握并能够灵活使用同步互斥机制了解并能够较灵活地使用IO技术【实验要求】● 基于线程的生产者-消费者的合作问题– 其中(生产者)从外设获取数据进行生产– 另外(消费者)消费后进行输出,并存储输出结果。●在Linux环境下使用POSIX库进行设计实现●鼓励使用QT进行图形化显示●根据情况决定是否进行答辩●可以2人一组,但不能超过2人,在报告中必须要有明确分工【问题描述】 ●完成N个生产者和M个消费者线程之间的并发控制,N、M不低于30,数据发送和接收缓冲区尺寸不小于20个(每个产品占据一个)。 ●其中生产者线程1、3、5、7、9生产的产品供所有奇数编号的消费..
阅读全文
摘要:Linux在用fork创建进程时,为子进程申请了堆栈、BSS区、全局变量、和代码段等资源。而用pthread_create创建线程时,用户空间分配的资源比线程少得多。可以说,线程就是轻量级的进程。1.函数 pthread_create()用来创建一个新的线程。其函数声明如下:1 /*come from /usr/include/pthread.h*/2 extern int pthread_create (pthread_t *__restrict __newthread,3 __const pthread_attr_t *__restrict __attr,4 ...
阅读全文
摘要:客户端向服务器发出连接请求后,服务器端写入数据发送给客户端,在客户端显示。server: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 11 #define MAXSIZE 102412 13 int main(int argc, char* argv[])14 {15 int sockfd, new_fd;16 struct sockaddr_in server_addr;17 struct so...
阅读全文
摘要:如果在Linux Terminal 里面 man system 大家可以看到system()函数的用法,非常简单:函数声明如下:int system(const char *command); 函数失败则返回-1,成功后返回0。 例:system("echo hello > hello.txt") /*将hello 写入到hello.txt*/
阅读全文
摘要:在ubuntu12.04下的共享内存+多线程+信号量练习实例。问题:程序要求用多线程+共享内存+信号量,实现将一个文件中的内容写入到另一个空白文件中(读与写的操作必须分在两个线程中完成),要求文件内容的大小要远大于所用共享内存的大小。分析:题目要求将一个文件(假设为in)中的数据存入到另一个空白文 件(假如为out)中,而且要求共享内存的大小要小于文件传输内容的大小,因此我们就需要利用有限大小的共享内存和文件指针将in中的数据循环多次倒入到 out文件中,而为了解决重复写入或是漏写等线程调度混乱造成的问题,需要在其中使用信号量加以同步控制。 1 /********************* 2
阅读全文
摘要:/*keyboardview.c*/#include #include #include #include #include #include int main (){ int keys_fd; int pipes[2]; struct input_event t; char buf[100]; int pid,pid1; int nread; int key_code; if(pipe(pipes) < 0) { printf("%s\n","pipes error!" ); exit(EXIT_FAILURE...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 int main(int argc, char* argv[])10 {11 int running = 1;12 int shid;13 int semid;14 int value;15 int read_num;16 FILE *stream;17 char* sharem=NULL;18 struct sembuf sem_b;19 sem_b.sem_n...
阅读全文

浙公网安备 33010602011771号