摘要:
一、利用select多路复用I/O的Web服务应用模型/* 可读、可写、异常三种文件描述符集的申明和初始化。*/ fd_set readfds, writefds, exceptionfds; FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptionfds); int max_fd; /* socket配置和监听。*/ sock = socket(...); bind(sock, ...); listen(sock, ...); /* 对socket描述符上发生关心的事件进行注册。*/ FD_SET(&r 阅读全文
posted @ 2014-03-21 20:23
samu
阅读(719)
评论(0)
推荐(0)
摘要:
#include #include int main(){ FILE* stream = popen ("sort", "w"); fprintf (stream, "This is a test.\n" ); fprintf (stream, "Hello, world.\n"); fprintf (stream, "My dog has fleas.\n"); fprintf (stream, "This program is great.\n"); fprintf (s 阅读全文
posted @ 2014-03-21 19:55
samu
阅读(220)
评论(0)
推荐(0)
摘要:
#include #include #include #include int main(){ int fds[2]; pid_t pid; pipe( fds ); pid = fork(); if( pid == (pid_t)0 ) { close( fds[1] ); dup2(fds[0], STDIN_FILENO ); execlp( "sort", "sort", 0 ); } ... 阅读全文
posted @ 2014-03-21 19:51
samu
阅读(246)
评论(0)
推荐(0)
摘要:
flags must include read,write,execute permission.for examples:semget( 3333, 1, IPC_CREAT | IPC_EXCL | 0666 );if there is not a '0666', then 'semop' wait will succed always. 阅读全文
posted @ 2014-03-21 14:10
samu
阅读(174)
评论(0)
推荐(0)
摘要:
#include #include #include int main (){int segment_id;char* shared_memory;struct shmid_ds shmbuffer;int segment_size;const int shared_segment_size = 0x6400;/* Allocate a shared memory segment. */segment_id = shmget (IPC_PRIVATE, shared_segment_size,IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);/* Attach 阅读全文
posted @ 2014-03-20 20:30
samu
阅读(392)
评论(0)
推荐(0)
摘要:
Shared memory permits processes to communicate by simply reading and writing to a specified memory location.Mapped memory is similar to shared memory, except that it is associated with a file in the filesystem.Pipes permit sequential communication from one process to a related process.FIFOs are simi 阅读全文
posted @ 2014-03-20 20:18
samu
阅读(164)
评论(0)
推荐(0)
摘要:
#include int thread_flag;pthread_cond_t thread_flag_cv;pthread_mutex_t thread_flag_mutex;void initialize_flag (){/* Initialize the mutex and condition variable.pthread_mutex_init (&thread_flag_mutex, NULL);pthread_cond_init (&thread_flag_cv, NULL);/* Initialize the flag value. */thread_flag 阅读全文
posted @ 2014-03-20 20:10
samu
阅读(197)
评论(0)
推荐(0)
摘要:
#include #include #include struct job {/* Link field for linked list.struct job* next;*//* Other fields describing work to be done... */};/* A linked list of pending jobs.struct job* job_queue;*//* A mutex protecting job_queue. */pthread_mutex_t job_queue_mutex = PTHREAD_MUTEX_INITIALIZER;/* A semap 阅读全文
posted @ 2014-03-20 20:07
samu
阅读(189)
评论(0)
推荐(0)
摘要:
[(lambda x: x*x)(x) for x in range(10)]Or better yet:[x*x for x in range(10)] 阅读全文
posted @ 2014-03-19 19:47
samu
阅读(157)
评论(0)
推荐(0)
摘要:
约瑟夫环问题: 输入:1)总共人数;2)每次被杀的序号数; 输出:最后一个活着的序号python代码如下:n=int (input('please input the number of people:') )k=int (input('please input the discard number:'))a=[]for i in range(n): a.append(i+1)print 'all the serial number of people:'print ai=0j=1while len(a)>1: if j==k: d... 阅读全文
posted @ 2014-03-19 18:35
samu
阅读(186)
评论(0)
推荐(0)
浙公网安备 33010602011771号