原创 多線程實現對同一個或多個文件的讀寫操作

程序用途:實現多個線程對同一文件的讀寫操作 程序代碼:test.c /*該程序在Ubuntu下測試通過*/ #include<stdio.h> #include<pthread.h> #include<sys/types.h> #in

原创 字符串hash函數

基本概念 所謂完美哈希函數,就是指沒有衝突的哈希函數,即對任意的 key1 != key2 有h(key1) != h(key2)。 設定義域爲X,值域爲Y, n=|X|,m=|Y|,那麼肯定有m>=n,如果對於不同的key1,key2屬

原创 使用parted創建分區

今天在網上查找分區方法,發現都是用的fdisk,但自己使用總是出錯,後來請求大神幫忙,發現了一個好用的工具,這裏把具體的使用過程記錄下來。 [root@pc160 ~]# parted /dev/sda GNU Parted 3.1 使用

原创 linux中fork()函數詳解(原創!!實例講解)

轉自:http://blog.csdn.net/jason314/article/details/5640969 一、fork入門知識      一個進程,包括代碼、數據和分配給進程的資源。fork()函數通過系統調用創建一個與原來

原创 最低公共祖先Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definitio

原创 linux多進程通信

1. 信號量機制實現進程通信: 先看一個例子摘自:http://blog.chinaunix.net/uid-23215128-id-2938280.html 使用sem_open,sem_unlink,sem_getvalue,sem_

原创 Majority Element I, II

Majority Element Given an array of size n, find the majority element. The majority element is the element that appea

原创 n皇后問題

N-Queens:來自leetcode Follow up for N-Queens problem. Now, instead outputting board configurations, return the total num

原创 makefile使用教程

來自:http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ A Simple Makefile Tutorial Makefiles are a simple way t

原创 各種二分查找算法總結

1. 最基本的二分查找算法: 在已排好序的vector中查找是否存在target bool findData(vector<int> &nums, int target){ if(nums.size()==0) return fal

原创 epoll 的accept , read, write(重要)

在一個非阻塞的socket上調用read/write函數, 返回EAGAIN或者EWOULDBLOCK(注: EAGAIN就是EWOULDBLOCK) 從字面上看, 意思是: * EAGAIN: 再試一次 * EWOULDBLOCK:

原创 sendmsg和recvmsg

已經工作了接近一年的時間,工作之餘也只能看看書,瞭解一下相關的技術細節,在網絡設備公司不可避免的要和socket打交道,但通常都是調用公司封裝好的接口,沒有去考慮這些封裝背後的工作,回過頭來看真的覺得進步很小,我只能逼自己看看書,看看一些

原创 linux下select使用

在Linux中,我們可以使用select函數實現I/O端口的複用,傳遞給 select函數的參數會告訴內核:       •我們所關心的文件描述符       •對每個描述符,我們所關心的狀態。(我們是要想從一個文件描述符中讀或者寫,還

原创 MD5校驗

(一)來自:http://www.cnblogs.com/zhenjing/p/openssl.html OpenSSL http://www.openssl.org/ OpenSSL整個軟件包大概可以分成三個主要的功能部分:密碼算法

原创 二叉樹後續遍歷算法

二叉樹後續遍歷非遞歸算法: void BT_PostOrderNoRec(pTreeT root) { stack<treeT *> s; pTreeT pre=NULL; //pre指針是重點 whil