Something about Cloud Computing
Learn about cloud computing
From: http://open.eucalyptus.com/learn
What is cloud computing?
Cloud computing is the access to computers and their functionality via the Internet or a local area network. Users of a cloud request this access from a set of web services that manage a pool of computing resources (i.e., machines, network, storage, operating systems, application development environments, application programs). When granted, a fraction of the resources in the pool is dedicated to the requesting user until he or she releases them. It is called “cloud computing” because the user cannot actually see or specify the physical location and organization of the equipment hosting the resources they are ultimately allowed to use. That is, the resources are drawn from a “cloud” of resources when they are granted to a user and returned to the cloud when they are released. A “cloud” is a set of machines and web services that implement cloud computing.
What is the relationship between virtualization and cloud computing?
Virtualization is the ability to run “virtual machines” on top of a “hypervisor.” A virtual machine (VM) is a software implementation of a machine (i.e., a computer) that executes programs like a physical machine. Each VM includes its own kernel, operating system, supporting libraries and applications. A hypervisor provides a uniform abstraction of the underlying physical machine. Multiple VMs can execute simultaneously on a single hypervisor. The decoupling of the VM from the underlying physical hardware allows the same VM to be started on different physical machines. Thus virtualization is seen as an enabler for cloud computing, allowing the cloud computing provider the necessary flexibility to move and allocate the computing resources requested by the user wherever the physical resources are available.
How are clouds classified?
Given the broad definition of the term “cloud,” the current taxonomy differentiates clouds both in terms of cloud service offerings and cloud types. When categorizing cloud service offerings we often refer to clouds in terms of “service style“ depending on the portion of the software stack delivered as a service. Here we discuss the most common service styles referred to by the acronyms IaaS, PaaS, and SaaS. Cloud ”types“ (including public, private, and hybrid) refer to the nature of access and control with respect to use and provisioning of virtual and physical resources.
What are the most popular cloud service styles?
IaaS
IaaS (Infrastructure as a Service) style clouds provide access to collections of virtualized computer hardware resources, including machines, network, and storage. With IaaS, users assemble their own virtual cluster on which they are responsible for installing, maintaining, and executing their own software stack.
PaaS
PaaS (Platform as a Service) style clouds provide access to a programming or runtime environment with scalable compute and data structures embedded in it. With PaaS, users develop and execute their own applications within an environment offered by the service provider.
SaaS
SaaS (Software as a Service) style clouds deliver access to collections of software application programs. SaaS providers offer users access to specific application programs controlled and executed on the provider’s infrastructure. SaaS is often referred to as “Software on Demand.”
What are cloud types?
Public cloud
Public clouds provide access to computing resources for the general public over the Internet. The public cloud provider allows customers to self-provision resources typically via a web service interface. Customer’s rent access to resources as needed on a pay-as-you-go basis. Public clouds offer access to large pools of scalable resources on a temporary basis without the need for capital investment in data center infrastructure.
Private cloud
Private clouds give users immediate access to computing resources hosted within an organization’s infrastructure. Users self-provision and scale collections of resources drawn from the private cloud, typically via web service interface, just as with a public cloud. However, because it is deployed within the organization’s existing data center—and behind the organization’s firewall—a private cloud is subject to the organization’s physical, electronic, and procedural security measures and thus offers a higher degree of security over sensitive code and data. In addition, private clouds consolidate and optimize the performance of physical hardware through virtualization, and can thus markedly improve data center efficiency while reducing operational expense.
Hybrid cloud
A hybrid cloud combines computing resources (e.g., machines, network, storage, etc.) drawn from one or more public clouds and one or more private clouds at the behest of its users.
Why Cloud Computing?
Cloud computing is seen by some as an important forward-looking model for the distribution and access of computing resources because it offers these potential advantages:
- Self-service provisioning: Allows users to deploy their own sets of computing resources (machines, network, storage, etc.) as needed without the delays and complications typically involved in resource acquisition; IT supports ongoing customization and enhancement of cloud user experience, while monitoring, managing, and expanding as required the underlying cloud infrastructure.
- Scalability: Decouples the fluctuating needs of individual users from typical infrastructure constraints, thus easily accommodating rapid increases or decreases in resource demand.
- Reliability and fault-tolerance: IT can focus on improving critical pieces of infrastructure to achieve pre-determined levels of reliability. Policies addressing expected levels of reliability can be continuosly reassessed and updated without user involvement.
- Optimization/Consolidation: Maximizes the usage and increases the efficiency of existing infrastructure resources. Extends infrastructure lifecycle. Reduces capital expenditure.
- QoS (Quality of Service): Allows IT to dynamically reassess the SLA associated with users or groups of users for the resources allocated. Allows the organization to react quickly to changing conditions without unnecessary user involvement or knowledge.
- Well defined API: Using a well-defined and stable industry standard API avoids locking and ensures interoperability with an ever-growing number of tools and cloud service providers.
- As-needed availability: Aligns resource expenditure with actual resource usage thus allowing the organization to pay only for the resources required, when they are required.
又当TA了
老板资金不足了,所以这学期改当TA了。系里给我分了CIS450。周三第一天上课,我现身了下,一进教室,看到黑压压的一片,目测有五十个学生左右。和任课老师谈了各种要求,这课负担不轻啊:每周一个quiz,一学期五六个homework,若干programming assignment,每周五lab hour得现身(早上九点半)。幸好我这学期没有选课,不然得折腾死。CIS450讲的内容比较泛,计算机组成原理,本科时没上过这课。看了下大纲,翻了下课件,大部分内容我应该都看过,从其他书或课上了解的。但很多都给忘了,需要时得翻出来复习下。quiz和homework都会给sample answer,这样能减轻些负担。
改作业什么的最烦了,所以我不喜欢当TA,但现在没得选,当了就认真对待吧。
Ubuntu 10.04图形界面无法登录,密码是对的
前几天调整台式机的硬盘分区,之前的分区很不合理。结果Windows 7对硬盘分区的个数有限制,机器上现在的分区有六个(windows 7三个分区,ubuntu占了两个primary分区,还有一个系统OEM分区),在shrink一个分区之后就无法新建分区了。想尽了各种办法,删除个别分区,扩大分区,都不管用。最后逼得没办法,就只有把后四个全删了,再重新分。之前装的Ubuntu10.04也没了,只好重新装。我觉得我就是喜欢瞎折腾,还带有点洁癖。看到不整齐,结构不对称的东西,我就不舒服,非要把它们弄到我看得爽了才行。这样的例子太多了,浪费了我好多时间。
Ubuntu 10.04没了,再装一个,打算试个新的版本。12.04的还没出,据说4月份会出。10.04是个LTS版本,支持到2013年。而12.04据说会支持五年。可以从10.04直接升到12.04,不过过程估计会不大顺畅,毕竟这俩之间隔了好几个版本。干脆试个最新的吧,11.10。装了之后,发现新版本fancy好多,但除了好看点之外似乎没发现其他亮点。有一个变化我挺喜欢,绑定的email客户端变成了Thunderbird,这是我用了多年的客户端,比起那个Evolution好多了。虽然如此,但我很不喜欢Ubuntu绑定这些email,chat,broadcast客户端软件。这也是间接导致标题中指明的问题的原因。用惯了以前的,对Unity很不习惯。menu bar没了,变成了global menu,位于屏幕左方;Synaptic Package Manager也没了,软件的安装都集成到了Ubuntu Software Center;虽然global menu也可以和menu bar一样,加入一些程序的快捷方式,但找出这些程序比较费功夫,要么在已安装的程序中搜索,要么一个个浏览下来,这样就很麻烦了,个人非常不喜欢这样的;那个global还是autohide,位置还不能变动,这一功能貌似从Mac系统那学来的,但我不喜欢autohide,也不喜欢放在左边;等等。除了各种不惯不方便之外,另一个大问题是Unity不大稳定,有bug,比如搜索程序没搜到,明明都安装了,还有我先点了“Media Apps”,然后点“More Apps”查找已安装的程序,结果打开的还是我点“Media Apps”的东西。最后碰到的一个bug让我彻底放弃了Ubuntu 11.10。我试着用3D桌面,设置好后,把其他窗口都关了,然后看桌面,什么东西都没了,而以前又没用过,不知道有没有什么快捷键。那个global menu bar也死活不出来。不想再折腾了,也不想花那么多的时间去适应这些新玩意,果断卸了,装回Ubuntu 10.04。
装回10.04之后,愈发觉得之前说的那些绑定的email,chat,broadcast客户端软件让人看着很不爽,而且他们还出现在右上角的那些application applet indicator离。我的洁癖强迫症又犯了,google了去掉这些玩意的办法,把Empathy,Evolution,Gwibber全卸了,在Synaptic Package Manager用了“complete removal”。被能够拜托这些东西的兴奋劲给迷惑了,没有注意看弹出的dependency提醒窗口,果然各种“OK”。整得差不多了,重启再登录。在图形界面的登录窗口里输了密码,结果却没有登录系统,还是出现这个登录窗口。不是密码错误,因为没看到authentication failure的提示。试了N次,还是不行。重启用text mode登录,却没有问题。Google之。看过很多帖子之后,发现不少人跟我一样不喜欢上面那些绑定的软件,也注定着不少人碰到了我碰到的问题。最开始以为问题的原因是卸载Evolution时(complete removal)把一些其他程序用到的服务也给卸载了。重装了Evolution,重新登录,发现没有用。再找原因,有人说试下重装gnome-applets。试了,这次成功了。gnome-applets依赖于Evolution的一些服务,但complete removal时把这些服务给删了,进而导致它们的依赖着也被卸载了,包括gnome-applets。
我就是爱折腾,没事找事。。。
APUE2e Exercise 16.3 – Solution B
Code for client side is in Figure 16.14 in APUE2e, Page 568.
To compile the program, check this post: posix thread相关函数的编译(undefined reference to `pthread_create’)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | /** * apue-chap16: exercise16-3B.c * * Description: multiple threads, multiple endpoint to provide "ruptime" service * * Created On: Jan 11, 2012 * * @author: Huang Zhu * * @email: zhuhuang.zp@gmail.com */ #include <apueerr.h> #include <pthread.h> #include <netdb.h> #include <errno.h> #include <fcntl.h> #include <stdlib.h> #include <syslog.h> #include <sys/socket.h> #include <sys/resource.h> #include <sys/select.h> #define BUFLEN 128 #define QLEN 10 #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif typedef struct Server_FD { int fd; struct addrinfo addr; } Server_FD; int initserver(int type, const struct sockaddr *addr, socklen_t alen, int qlen) { int sockfd, err; int reuse = 1; if((sockfd = socket(addr->sa_family, type, 0)) < 0) return(-1); if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)) < 0){ err = errno; goto errout; } if(bind(sockfd, addr, alen) < 0){ err = errno; goto errout; } if(type == SOCK_STREAM || type == SOCK_SEQPACKET){ if(listen(sockfd, qlen) < 0){ err = errno; goto errout; } } return(sockfd); errout: close(sockfd); errno = err; return(-1); } void daemonize(const char *cmd) { int i, fd0, fd1, fd2; pid_t pid; struct rlimit rl; struct sigaction sa; /* * Clear file creation mask. */ umask(0); /* * Get maximum number of file descriptors. */ if (getrlimit(RLIMIT_NOFILE, &rl) < 0) err_quit("%s: can't get file limit", cmd); /* * Become a session leader to lose controlling TTY. */ if ((pid = fork()) < 0) err_quit("%s: can't fork", cmd); else if (pid != 0) /* parent */ exit(0); setsid(); /* * Ensure future opens won't allocate controlling TTYs. */ sa.sa_handler = SIG_IGN; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGHUP, &sa, NULL) < 0) err_quit("%s: can't ignore SIGHUP"); if ((pid = fork()) < 0) err_quit("%s: can't fork", cmd); else if (pid != 0) /* parent */ exit(0); /* * Change the current working directory to the root so * we won't prevent file systems from being unmounted. */ if (chdir("/") < 0) err_quit("%s: can't change directory to /"); /* * Close all open file descriptors. */ if (rl.rlim_max == RLIM_INFINITY) rl.rlim_max = 1024; for (i = 0; i < rl.rlim_max; i++) close(i); /* * Attach file descriptors 0, 1, and 2 to /dev/null. */ fd0 = open("/dev/null", O_RDWR); fd1 = dup(0); fd2 = dup(0); /* * Initialize the log file. */ openlog(cmd, LOG_CONS, LOG_DAEMON); if (fd0 != 0 || fd1 != 1 || fd2 != 2) { syslog(LOG_ERR, "unexpected file descriptors %d %d %d", fd0, fd1, fd2); exit(1); } } void* serve_client(void* fd) { int clientfd; int sockfd; FILE *fp; char buf[BUFLEN]; pthread_t tid; tid = pthread_self(); sockfd = (int)fd; clientfd = accept(sockfd, NULL, NULL); //we don't care about client's identity if(clientfd < 0){ syslog(LOG_ERR, "ruptimed: accept error: %s", strerror(errno)); exit(1); } //popen, pclose: apue2e, page 503 if((fp = popen("/usr/bin/uptime", "r")) == NULL){ sprintf(buf, "error: %s\n", strerror(errno)); send(clientfd, buf, strlen(buf), 0); }else{ while(fgets(buf, BUFLEN, fp) != NULL) send(clientfd, buf, strlen(buf), 0); //prove that the thread works sprintf(buf, " thread id: %ld\n", tid); send(clientfd, buf, strlen(buf), 0); pclose(fp); } close(clientfd); return((void*)0); } void serve(fd_set *set, int maxfd, Server_FD *fdarray, int maxindex) { int serverfd; int ready; int i; pthread_t tid; int err; for(;;){ if((ready = select(maxfd+1, set, NULL, NULL, NULL)) > 0){ for(i = 0; i < maxindex; i++) { serverfd = fdarray[i].fd; if(FD_ISSET(serverfd, set)){ err = pthread_create(&tid, NULL, serve_client, (void *)serverfd); if(err != 0){ syslog(LOG_ERR, "ruptimed: pthread_create error: %s", strerror(err)); } } } } } } int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct addrinfo hint; int sockfd, err, n; char *host; fd_set sockset; //read sets int maxfd = -1; //maximum socket descriptor Server_FD fdarray[FD_SETSIZE]; //array to store server sockets waiting for connection requests int maxindex = 0; //the index past the last effective element in array fdarray if(argc != 1) err_quit("usage: ruptimed"); #ifdef _SC_HOST_NAME_MAX n = sysconf(_SC_HOST_NAME_MAX); if(n < 0) #endif n = HOST_NAME_MAX; host = malloc(n); if(host == NULL) err_sys("malloc error"); if(gethostname(host, n) < 0) err_sys("gethostname error"); printf("Host Name: %s\n", host); daemonize("ruptimed"); hint.ai_flags = AI_CANONNAME; hint.ai_family = 0; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = 0; hint.ai_addrlen = 0; hint.ai_canonname = NULL; hint.ai_addr = NULL; hint.ai_next = NULL; if((err = getaddrinfo(host, "ruptime", &hint, &ailist)) != 0){ syslog(LOG_ERR, "ruptimed: getaddrinfo error: %s", gai_strerror(err)); exit(1); } FD_ZERO(&sockset); for(aip = ailist; aip != NULL; aip = aip->ai_next){ if((sockfd = initserver(SOCK_STREAM, aip->ai_addr, aip->ai_addrlen, QLEN)) >= 0){ if(sockfd > maxfd) maxfd = sockfd; //add the socket to fd_set sockset FD_SET(sockfd, &sockset); //add the socket and corresponding address to array fdarray fdarray[maxindex].fd = sockfd; fdarray[maxindex].addr = *aip; maxindex++; } } if(maxfd >=0) serve(&sockset, maxfd, fdarray, maxindex); exit(1); } |
APUE2e Exercise 16.3 – Solution A
Below is the code for the server side. Code for client side is in Figure 16.14 in APUE2e, Page 568.
To compile the program, check this post: posix thread相关函数的编译(undefined reference to `pthread_create’)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | /** * apue-chap16: exercise16-3A.c * * Description: single thread, multiple endpoint to provide "ruptime" service * * Created On: Jan 11, 2012 * * @author: Huang Zhu * * @email: zhuhuang.zp@gmail.com */ #include <apueerr.h> #include <netdb.h> #include <errno.h> #include <fcntl.h> #include <stdlib.h> #include <syslog.h> #include <sys/socket.h> #include <sys/resource.h> #include <sys/select.h> #define BUFLEN 128 #define QLEN 10 #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif typedef struct Server_FD { int fd; struct addrinfo addr; } Server_FD; int initserver(int type, const struct sockaddr *addr, socklen_t alen, int qlen) { int sockfd, err; int reuse = 1; if((sockfd = socket(addr->sa_family, type, 0)) < 0) return(-1); if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)) < 0){ err = errno; goto errout; } if(bind(sockfd, addr, alen) < 0){ err = errno; goto errout; } if(type == SOCK_STREAM || type == SOCK_SEQPACKET){ if(listen(sockfd, qlen) < 0){ err = errno; goto errout; } } return(sockfd); errout: close(sockfd); errno = err; return(-1); } void daemonize(const char *cmd) { int i, fd0, fd1, fd2; pid_t pid; struct rlimit rl; struct sigaction sa; /* * Clear file creation mask. */ umask(0); /* * Get maximum number of file descriptors. */ if (getrlimit(RLIMIT_NOFILE, &rl) < 0) err_quit("%s: can't get file limit", cmd); /* * Become a session leader to lose controlling TTY. */ if ((pid = fork()) < 0) err_quit("%s: can't fork", cmd); else if (pid != 0) /* parent */ exit(0); setsid(); /* * Ensure future opens won't allocate controlling TTYs. */ sa.sa_handler = SIG_IGN; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGHUP, &sa, NULL) < 0) err_quit("%s: can't ignore SIGHUP"); if ((pid = fork()) < 0) err_quit("%s: can't fork", cmd); else if (pid != 0) /* parent */ exit(0); /* * Change the current working directory to the root so * we won't prevent file systems from being unmounted. */ if (chdir("/") < 0) err_quit("%s: can't change directory to /"); /* * Close all open file descriptors. */ if (rl.rlim_max == RLIM_INFINITY) rl.rlim_max = 1024; for (i = 0; i < rl.rlim_max; i++) close(i); /* * Attach file descriptors 0, 1, and 2 to /dev/null. */ fd0 = open("/dev/null", O_RDWR); fd1 = dup(0); fd2 = dup(0); /* * Initialize the log file. */ openlog(cmd, LOG_CONS, LOG_DAEMON); if (fd0 != 0 || fd1 != 1 || fd2 != 2) { syslog(LOG_ERR, "unexpected file descriptors %d %d %d", fd0, fd1, fd2); exit(1); } } void serve(fd_set *set, int maxfd, Server_FD *fdarray, int maxindex) { int clientfd; int serverfd; int ready; FILE *fp; char buf[BUFLEN]; int i; for(;;){ //A socket with pending connect requests will appear to be readable. Use only read sets for select. if((ready = select(maxfd+1, set, NULL, NULL, NULL)) > 0){ for(i = 0; i < maxindex; i++) { serverfd = fdarray[i].fd; if(FD_ISSET(serverfd, set)){ clientfd = accept(serverfd, NULL, NULL); //we don't care about client's identity if(clientfd < 0){ syslog(LOG_ERR, "ruptimed: accept error: %s", strerror(errno)); exit(1); } //popen, pclose: apue2e, page 503 if((fp = popen("/usr/bin/uptime", "r")) == NULL){ sprintf(buf, "error: %s\n", strerror(errno)); send(clientfd, buf, strlen(buf), 0); }else{ while(fgets(buf, BUFLEN, fp) != NULL) send(clientfd, buf, strlen(buf), 0); pclose(fp); } close(clientfd); } } } } } int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct addrinfo hint; int sockfd, err, n; char *host; fd_set sockset; //read sets int maxfd = -1; //maximum socket descriptor Server_FD fdarray[FD_SETSIZE]; //array to store server sockets waiting for connection requests int maxindex = 0; //the index past the last effective element in array fdarray if(argc != 1) err_quit("usage: ruptimed"); #ifdef _SC_HOST_NAME_MAX n = sysconf(_SC_HOST_NAME_MAX); if(n < 0) #endif n = HOST_NAME_MAX; host = malloc(n); if(host == NULL) err_sys("malloc error"); if(gethostname(host, n) < 0) err_sys("gethostname error"); printf("Host Name: %s\n", host); daemonize("ruptimed"); hint.ai_flags = AI_CANONNAME; hint.ai_family = 0; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = 0; hint.ai_addrlen = 0; hint.ai_canonname = NULL; hint.ai_addr = NULL; hint.ai_next = NULL; if((err = getaddrinfo(host, "ruptime", &hint, &ailist)) != 0){ syslog(LOG_ERR, "ruptimed: getaddrinfo error: %s", gai_strerror(err)); exit(1); } FD_ZERO(&sockset); for(aip = ailist; aip != NULL; aip = aip->ai_next){ if((sockfd = initserver(SOCK_STREAM, aip->ai_addr, aip->ai_addrlen, QLEN)) >= 0){ if(sockfd > maxfd) maxfd = sockfd; //add the socket to fd_set sockset FD_SET(sockfd, &sockset); //add the socket and corresponding address to array fdarray fdarray[maxindex].fd = sockfd; fdarray[maxindex].addr = *aip; maxindex++; } } if(maxfd >=0) serve(&sockset, maxfd, fdarray, maxindex); exit(1); } |
posix thread相关函数的编译(undefined reference to `pthread_create’)
在解APUE2e Exercise 16.3的问题时,尝试着用thread来应答client请求(代码见exercise16-3b.c)。当发现server的某个socket有请求到达时(select函数),创建一个thread,让这个thread accept客户端的请求,然后发送相应的信息。在eclipse上写完程序后,准备编译,却得到undefined reference to `pthread_create’的错误。本以为是参数写错了,查了多遍,都没有问题。然后尝试着用gcc编译,也得到一样的错误信息。Google一下才知道,pthread所在的library并不在编译路径里,需要先链接对应的library才行。
解决办法:
eclipse:
Project Properties -> C/C++ Build -> Settings -> Tool Setting -> GCC C Linker -> Libraries -> Add ‘pthread’,如下图所示。
gcc:
加入编译选项lpthread,比如: gcc -o ruptimed exercise16-3b.c -lpthread。
又耳鸣了
昨晚洗完澡,坐电脑前敲代码,突然觉得右耳有点不对劲,果然接下来就耳鸣了。感觉像是有什么东西堵住一样,有点难受,听力也有一点点下降,左耳倒是没事。这情况暑假时曾发生过一次。那会去看了医生,医生说没事,没有发炎,很可能是进水了,给我开了药片和滴耳水。我记得只滴了几次药水,吃了俩药片,老是忘。不过没几天耳朵自己好了。这次估计也是进水吧,和上次的情况一样。上次拿的药还在,也没过期,将就用着。昨晚滴了药水,早上起来能感觉到很明显的耳鸣和堵塞感。滴了药水,吃了药片。到傍晚时稍微有点好转。等个一两天吧,自己应该会好的。
2011年买的书
到目前为止,2011年应该是我买书最多的一年,不管从价钱上,还是从数量上看。翻了一下,有以下这些:
小说类:
- 《His Dark Materials》三部曲:《The Golden Compass》,《The Subtle Knife》,《The Amber Spyglass》。这三本都看完了。
- 《Kingkiller Chronicles》两部:《The Name of the Wind》,《The Wise Man’s Fear》。没看。
技术类:
- 《The Design of The Unix Operating System》。看了一遍,有时间的话,想再看一遍。
- 《A Practical Guide to Linux Commands, Editors, and Shell Programming》。看了一些。今年会继续看,要把它完成。
- 《Understanding the Linux Kernel》。看了三章。今天会继续看,先把感兴趣的部分看了。
- 《Understanding Linux Network Internals》。没看。今年若有时间,会开始看的。优先级比较低。
- 《Introduction to Algorithms》。没看。今年打算认真看一遍。
- 《Programming Windows Phone 7 – Microsoft Silverlight Edition》。没看,刚买的。为了WP7开发而买的,作为参考书用。
- 《The C# Programming Language》。没看,刚买的。也是为了WP7开发买的,没学过C#,最近就会开始读。
面试类:
- 《Cracking the Coding Interview: 150 Programming Questions and Solutions》。看了大部分。剩下的最近会看完。
- 《The Google Resume》。没有看。
读书方面,今年读的也算比较多,不限于以上这些书,比如用手机和kindle就看了好几部小说和自传,《明朝那些事儿》,韩寒的作品,李开复和罗永浩的自传等等。技术方面的书,出来以上列的,还看了《Advanced Programming in the Unix Environment》和《C++ Primer》。APUE这书算是看第二遍,第一遍看的比较匆忙,没有练书上的代码,所以有了第二遍。第二遍还没有完成,过了一半吧,今年上半年要完成它。《C++ Primer》完整地看了一遍,并为了准备面试浏览了两遍。这书主要是理论,要记得的东西太多。
列一下2012要读的书,包括已读的,在读的,未读的:
- 《Advanced Programming in the Unix Environment》
- 《A Practical Guide to Linux Commands, Editors, and Shell Programming》
- 《Understanding the Linux Kernel》
- 《Understanding Linux Network Internals》
- 《Introduction to Algorithms》
- 《Programming Windows Phone 7 – Microsoft Silverlight Edition》
- 《The C# Programming Language》
- 《Cracking the Coding Interview: 150 Programming Questions and Solutions》
任务很艰巨。
革命尚未成功,同志仍需努力。
人生就是不停的战斗。
新年快乐
洗了个澡就跨年了,从2011年洗到2012年。
2011年过得,怎么说呢,不是很满意。就不总结了,let them go。
2012年,希望能更好地实现自我价值。人生就是不停的战斗。
新年快乐!
学Windows Phone App开发
学了七年多的本专业,但却从没开发过一个实际的应用,我指的是那种可以release。一直以来都是写在命令行下运行的小程序,学的也不是应用层的东西,都是系统层的编程,总觉得少些什么。我要改变这一现状,利用些时间做些实际的东西出来。最开始想用Qt开发Linux上的应用程序,正好练练我学的Unix编程,但同学说Qt已经被Nokia遗弃了,不会有什么前途。的确,还是学些有用的东西,以后说不定能用上。之前有段时间看了些Android编程,后来被我扔了。Android和iOS上的应用已经多如牛毛了,现在追赶估计不怎么有利可图了。打算试试Windows Phone,ms去年才开始发力移动市场,wp的机会应该比较多。没学过C#,不过现学应该不难。已经入了两本书,一般C#,一本Windows Phone。已经开始看MS提供的教学视频和文档,so far so good。先构思一些想做的app,把应用程序的界面框架搭好,剩下的功能就边学C#边实现。当然,Unix的东西我不会放,得深入学习,现在写的都是小打小闹的程序,大多数是APUE书上的例子或习题。我比较想往系统层次的编程发展,比如写服务器程序等,需要找些项目来试试,不能再停留在书本上,不然不会有多少长进。
还有一年半就毕业了,抓住剩下的时间做些让自己满意的事,不再犹豫。





最新评论