随笔分类 -  Linux

摘要:Booting and Shutdown 阅读全文
posted @ 2013-10-17 00:48 刘超觉先 阅读(821) 评论(0) 推荐(1) 编辑
摘要:一、基本原理 有时候我们需要实现一个公共的模块,需要对多个其他的模块提供服务,最常用的方式就是实现一个Socket Server,接受客户的请求,并返回给客户结果。 这经常涉及到如果管理多个连接及如何多线程的提供服务的问题,常用的方式就是连接池和线程池,基本流程如下: 首先服务器端有一个监听线程,不断监听来自客户端的连接。 当一个客户端连接到监听线程后,便建立了一个新的连接。 监听线程将新建立的连接放入连接池进行管理,然后继续监听新来的连接。 线程池中有多个服务线程,每个线程都监听一个任务队列,一个建立的连接对应一个服务任务,当服务线程发现有新的任务的时候,便用此连接向客户端提供服务。 一.. 阅读全文
posted @ 2010-09-12 16:30 刘超觉先 阅读(21232) 评论(4) 推荐(6) 编辑
摘要:经常需要Kill多个进程,这些进程包含共同的关键字,可以用一条命令Kill掉它们。 ps aux | grep "common" | cut –c 9-15 | xargs kill –9 管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。下面说说用管道符联接起来的几个命令: "ps aux" 查看所有进程的命令。这时检索出的进程将作为下一条命令grep "common"的输入。 "grep "common" 选出所有含有关键字"common"的进程。 &q 阅读全文
posted @ 2010-05-16 00:18 刘超觉先 阅读(7889) 评论(0) 推荐(0) 编辑
摘要:五种进程间通信的方式: 共享内存(shared memory):其允许多个进程通过读写同一块内存地址来相互通信。 内存映射(Mapped memory):其和共享内存相似,然而它是和文件系统上的一个文件相关联的。 管道(Pipe):其允许一个进程到另一个相关进程的顺序通信。 先入先出队列(FIFO):和管道类似,然而因为其对应于文件系统上的文件名,可以在两个不相关的进程间通信。 Socket:其允许在不同的计算机上的不同进程间通信。 1、共享内存(Shared Memory) 共享内存时进程间通信方式中最快的一种,因为进程是共享同一块内存。 内核并不提供对共享内存访问... 阅读全文
posted @ 2010-04-29 00:24 刘超觉先 阅读(2270) 评论(0) 推荐(0) 编辑
摘要:要想使用POSIX标准线程API(pthreads),需要连接libpthread.so库到程序中。 1、创建线程 进程中的每个线程都有一个线程号,类型为pthread_t。 用pthread_self函数可以返回当前线程的线程号。 线程号之间的比较可以用函数pthread_equal。 if (!pthread_equal (pthread_self (), other_thread)) pthread_join (other_thread, NULL); 每个线程执行一个线程函数: void * function(void *) 用函数pthr... 阅读全文
posted @ 2010-04-27 00:08 刘超觉先 阅读(1945) 评论(0) 推荐(0) 编辑
摘要:每个进程都有一个唯一的进程号。 每个进程都有一个父进程。 系统中的进程以树的形式组织,init进程(进程号为1)作为根。 进程0是调度进程,没有程序与之对应,是内核的一部分。 进程1是init进程,是在系统启动的阶段由内核启动的,对应/sbin/init程序,是普通的用户进程。 程序中可以通过getpid()得到进程号,通过getppid()得到父进程的进程号。 #include <stdio.h> #include <unistd.h> int main () { printf (“The process ID is %d\n”, (int) getpid... 阅读全文
posted @ 2010-04-25 21:46 刘超觉先 阅读(1562) 评论(0) 推荐(1) 编辑
摘要:1、同运行环境交互1.1、命令行当一个程序从shell启动的时候,其参数列表包括程序名称及所有的命令行参数% ls -s /其参数列表包含三项:第一项是程序名称ls,第二项和第三项分别是两个命令行参数,-s和/main函数可以通过argc和argv两个参数来访问命令行参数列表:argc是命令行参数的个数,argv是命令行参数字符串指针所组成的数组#include <stdio.h>int main (int argc, char* argv[]){ printf (“The name of this program is ‘%s’.\n”, argv[0]); printf (“T 阅读全文
posted @ 2010-04-25 00:23 刘超觉先 阅读(1229) 评论(0) 推荐(1) 编辑
摘要:1、用GCC编译1.1、创建源文件(main.c) C 源文件 - main.c#include <stdio.h>#include “reciprocal.hpp”int main (int argc, char **argv){ int i; i = atoi (argv[1]); printf (“The reciprocal of %d is %g\n”, i, reciprocal (i)); return 0;}(reciprocal.cpp) C++ 源文件 - reciprocal.cpp#include <cassert>#include “recip 阅读全文
posted @ 2010-04-22 00:30 刘超觉先 阅读(1313) 评论(4) 推荐(1) 编辑
摘要:由于原书是英文的,因而笔记是英文的,大家敬请谅解吧。 1. Getting Started http://www.cnblogs.com/forfuture1978/archive/2010/02/11/1667457.html 2. Writing Good GNU/Linux Software http://www.cnblogs.com/forfuture1978/archive/2010/02/11/1667458.html 3. Processes http://www.cnblogs.com/forfuture1978/archive/2010/02/12/1667789.ht.. 阅读全文
posted @ 2010-02-25 13:08 刘超觉先 阅读(1274) 评论(0) 推荐(1) 编辑
摘要:6. Devices A device driver hides the hardware device’s communication protocols from the operating system and allows the system to interact with the device through a standardized interface. Processes can communicate with a device driver via file-like objects. 6.1 Device Types A character device re... 阅读全文
posted @ 2010-02-12 11:10 刘超觉先 阅读(819) 评论(0) 推荐(0) 编辑
摘要:5. Interprocess Communication Five types of interprocess communication: 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... 阅读全文
posted @ 2010-02-12 11:06 刘超觉先 阅读(844) 评论(0) 推荐(0) 编辑
摘要:4. Threads To use the POSIX standard thread API (pthreads), link libpthread.so to your program. 4.1. Thread Creation Each thread in a process is identified by a thread ID, pthread_t. The pthread_self function returns the thread ID of the current thread. This thread IDs can be compared with the p... 阅读全文
posted @ 2010-02-12 11:00 刘超觉先 阅读(1297) 评论(0) 推荐(0) 编辑
摘要:3. Processes Each process is identified by its unique process ID Every process has a parent process. Processes are arranged in a tree, with the init process at its root A program can obtain the process ID with getpid() and can obtain the process ID of its parent process with the getppid(). #incl... 阅读全文
posted @ 2010-02-12 10:48 刘超觉先 阅读(911) 评论(0) 推荐(0) 编辑
摘要:2. Writing Good GNU/Linux Software 2.1. Interaction With the Execution Environment 2.1.1. Command Line When a program is invoked from the shell, the argument list contains the entire both the name of the program and any command-line arguments provided. % ls -s / The argument list has three element.. 阅读全文
posted @ 2010-02-11 11:52 刘超觉先 阅读(715) 评论(0) 推荐(0) 编辑
摘要:1. Getting Started 1.1. Compiling with GCC 1.1.1. Create the source code files (main.c) C source file—main.c #include <stdio.h> #include “reciprocal.hpp” int main (int argc, char **argv) { int i; i = atoi (argv[1]); printf (“The reciprocal of %d is %g\n”, i, reciprocal (i)); return 0; } (rec.. 阅读全文
posted @ 2010-02-11 11:52 刘超觉先 阅读(973) 评论(0) 推荐(0) 编辑