摘要: 背景知识如果TCP客户同时处理两个输入: 标准输入和TCP套接字. 那么如果客户阻塞于标准输入期间(例如fgets()), 套接字收到的FIN或者RST信息就不会及时得到处理. 所以这里需要使用I/O复用, 是由select和poll这两个函数支持的.为了更好地理解I/O复用, 这里总结一下UNIX下的5种I/O模型的基本区别:阻塞式I/O : 默认情况下, 所有的套接字都是阻塞的. 一些慢系统调... 阅读全文
posted @ 2016-08-18 22:11 gremount 阅读(157) 评论(0) 推荐(0)
摘要: [编程题] 洗牌洗牌在生活中十分常见,现在需要写一个程序模拟洗牌的过程。 现在需要洗2n张牌,从上到下依次是第1张,第2张,第3张一直到第2n张。首先,我们把这2n张牌分成两堆,左手拿着第1张到第n张(上半堆),右手拿着第n+1张到第2n张(下半堆)。接着就开始洗牌的过程,先放下右手的最后一张牌,再放下左手的最后一张牌,接着放下右手的倒数第二张牌,再放下左手的倒数第二张牌,直到最后放下左手的第一张... 阅读全文
posted @ 2016-08-18 21:34 gremount 阅读(260) 评论(0) 推荐(0)
摘要: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 两个字符串A和B, 在A中查找是否出现过B, 如 阅读全文
posted @ 2016-08-15 19:49 gremount 阅读(150) 评论(0) 推荐(0)
摘要: 僵死进程存在的目的 和 需要处理的原因设置僵死进程的目的是维护子进程的信息, 以便父进程在以后的某个时刻获取. 但是留存的僵死进程会占用内核的空间, 最终可能导致耗尽进程资源. 所以还是需要处理这些僵死进程.处理僵死进程的方法在服务器子进程终止时, 给父进程发送了一个SIGCHLD信号,该信号是在子进程终止时,由内核发送给父进程的一个信号. 每个信号都有一个与之关联的处置, 也称为行为. 我们可以... 阅读全文
posted @ 2016-08-15 17:09 gremount 阅读(619) 评论(0) 推荐(0)
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 该题是要求合并两 阅读全文
posted @ 2016-08-14 22:47 gremount 阅读(147) 评论(0) 推荐(0)
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这道题如果有第21题 合并两个链表的基础就会比较容易,具体合并链表的时候有两种思路 (1)如果k个li 阅读全文
posted @ 2016-08-14 22:19 gremount 阅读(167) 评论(0) 推荐(0)
摘要: TCP客户与服务器进程之间发生的重大事件时间表TCP服务器socket() --- bind() --- listen() --- accept() --- read() --- write --- read() --- closeTCP客户socket() --- connect() --- write() --- read() --- close()套接字函数简介int socket(int... 阅读全文
posted @ 2016-08-13 17:29 gremount 阅读(505) 评论(0) 推荐(0)
摘要: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic 阅读全文
posted @ 2016-08-08 14:47 gremount 阅读(122) 评论(0) 推荐(0)
摘要: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2016-08-08 11:07 gremount 阅读(149) 评论(0) 推荐(0)
摘要: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are: 阅读全文
posted @ 2016-07-31 16:33 gremount 阅读(109) 评论(0) 推荐(0)