Modern Operating Systems 笔记 - Threads

fork pthread sed 线程 内核空间 操作系统 用户空间 进程

Thread Usage

  1. Multiple activities going on at once with the ability to share an address space
  2. Lighter weight than processes, easy to create and destroy.
  3. Overlap activities with substantial I/O to speeding up the application.
  4. Useful on systems with multiple CPUs.

Three ways to construct a server

  1. Thread. Parallelism, blocking system calls.
  2. Single-threaded process. No parallelism, blocking system calls.
  3. Finite-state machine. Parallelism, nonblocking system calles, use interrupts to simulate thread.

Classical Thread Model

Processes are used to group resources together; threads are the entities scheduled for execution on the CPU. There are no protection betwwen threads because (1) it’s impossible, and (2) it should not be nessessary.

While threads share one memory space, it takes fewer space to maintain a thread, including Program Counter, Registers, Stack and State.

Modern Operating Systems 笔记 - Processes

操作系统 进程 Unix Windows fork kill sed

pseudoparallelism

The illusion of parallelism while CPU is switching from process to process quickly.

The Process Model

process is an instance of an executing program, is the activity of a program.

If a program is running twice, it counts as two processes.

Process Creation

Processes are created when

  1. System init
  2. Process creation system call by a running process
  3. A user request to create a new process.
  4. Init of a batch job.

Modern Operating Systems 笔记 - Introduction

Unix Windows 操作系统

What is OS

  1. extendes machines : providing programmers(and programs) a clean abstract set of resources instead of the messy hardware
  2. resource manager : managing hardware resources

History of OS

The first digital computer was designed by Charles Babbage. Ada Lovelace was the first programmer(hired by Babbage).

1st Generation Vacuum Tubes

  • The first functioning digital computer, by John Atanasoff and Clifford Berry, Iowa State University.
  • Z3, Konrad Zuse, Berlin.
  • Colossus, a group at Bletchey Park, England
  • Mark I, Howard Aiken, Harvard
  • ENIAC, William Mauchley and J. Presper Eckert, University of Pennsylvania

Vim初级:配置和使用

Vim-Practice Bash Unix Vim sed 编译

Vim是从vi发展出来的一个文本编辑器。代码补全、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。和Emacs并列成为类Unix系统用户最喜欢的编辑器。

文档参见:http://vimdoc.sourceforge.net/htmldoc/

中文文档:http://vimcdoc.sourceforge.net/doc/

安装 Arch Linux

ArchLinux Linux 镜像 磁盘 网络 操作系统

本文介绍如何安装 Arch Linux,一个轻量级、简单的 Linux 发行版。

制作镜像并启动

Arch 官网下载 下载镜像(x86 和 x86_64是同一镜像)。 然后刻录 USB 安装盘

  • linux:

    dd if=/path/to/iso of=/dev/sdc  # 确认 sdc 为你的U盘
    
  • windows:

    1. 下载 dd4dos
    2. dd if=/path/to/iso of="\\.\G:" # 确认G盘为你的U盘

另外,有些 U 盘就是启动不了,换一个即可。

搜索引擎搭建:Heritrix + Lucene

搜索引擎 倒排索引 PageRank Web

采用 Heritix + Lucene 搭建搜索引擎原型,支持网站排名(PageRank)和倒排索引(Inverted Index),并评估其性能。

爬虫(Heritrix)

Heritrix 是用作 Web 归档的爬虫框架,java语言实现,具有 Apache License 自由软件许可。我们采用heritrix抓取网页数据。 可参照官方 Guide:https://webarchive.jira.com/wiki/display/Heritrix/Heritrix+3.0+and+3.1+User+Guide

Linux 下的触摸板设置

ArchLinux Linux X11 触摸板

Arch Linux 下的触摸板配置:基本设置、输入时禁止触摸板敲击、外接鼠标时禁用触摸板。

软件安装

安装 Synaptics 驱动:

pacman -S xf86-input-synaptics

xf86-input-synaptics 自带了命令行管理工具 synclient, 还可以继续安装图形化的管理工具比如 GPointing Device Settings 或者 KDE 的触摸板控制模块:

yaourt -S gpointing-device-settings
yaourt -S kcm_touchpad

环境配置

一般的设置工作可通过图形管理工具完成,如单击、双击、右键的识别,横向和纵向滚动、双指滚动。下面介绍一些高级配置。

基本触摸板配置

可通过修改 synaptics 的配置文件,修改触摸板配置。包括多指敲击、滚动、避免手掌触摸、精确度与快速滚动。

#file: /etc/X11/xorg.conf.d/50-synaptics.conf
Section "InputClass"
    Identifier "touchpad catchall"
    Driver "synaptics"
    MatchIsTouchpad "on"
        
    Option "TapButton1" "1"            #单指敲击产生左键事件
    Option "TapButton2" "2"            #双指敲击产生中键事件
    Option "TapButton3" "3"            #三指敲击产生右键事件
        
    Option "VertEdgeScroll" "on"       #滚动操作:横向、纵向、环形
    Option "VertTwoFingerScroll" "on"
    Option "HorizEdgeScroll" "on"
    Option "HorizTwoFingerScroll" "on"
    Option "CircularScrolling" "on"  
    Option "CircScrollTrigger" "2"
        
    Option "EmulateTwoFingerMinZ" "40" #精确度
    Option "EmulateTwoFingerMinW" "8"
    Option "CoastingSpeed" "20"        #触发快速滚动的滚动速度
        
    Option "PalmDetect" "1"            #避免手掌触发触摸板
    Option "PalmMinWidth" "3"          #认定为手掌的最小宽度
    Option "PalmMinZ" "200"            #认定为手掌的最小压力值
EndSection

通过 man synaptics 了解更多信息。注意:同时安装 kcm_synaptics 会覆盖掉该配置信息。

键入时禁止触摸板

键入时禁止触摸板可以避免焦点变化,影响当前的输入。 对于使用 startx 来启动的桌面系统,可以修改其 .xinitrc 初始化配置文件来完成:

syndaemon -t -k -i 2 -d &

其中的 -i 2 表示两秒空闲,即键盘事件后的两秒内不允许响应触摸板 Tap。更多信息请参照手册页:

man syndaemon

外接鼠标时禁用触摸板

在 arch linux 中,使用 udev 监测硬件的热拔插,通过修改其规则文件,来响应外接鼠标事件,从而禁用和启用触摸板。如下的规则文件,调用了 synclient。

#file: /etc/udev/rules.d/01-touchpad.rules
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/harttle/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/usr/bin/synclient TouchpadOff=1"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/harttle/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/usr/bin/synclient TouchpadOff=0"

注意:该文件中每个操作必须单独一行,可以使用 \ 来折行;SUBSYSTEMKERNEL 指定了设备 /dev/input/mouse[0-9](archwiki的中文页面中此处有误,我会找时间去修改)。了解更多 udev rules 语法:https://wiki.archlinux.org/index.php/Udev

开机时鼠标检测

PS/2 鼠标在开机时不会触发 udev 规则。我们做一个桌面环境的启动脚本,在 .xinitrc,profile 中调用,或者放在 KDE 的 Autostart 中:

#!/bin/bash
ids=`ls /dev/input/by-id | grep -E '.*-mouse'`
[ "$ids" ] && synclient TouchpadOff=1

触摸板识别错误

对于某些型号的机器,Arch 下触摸板识别会有问题(内核bug),官方建议从 AUR 安装 psmouse-alps-driver。受影响的机器有:

  • Acer Aspire 7750G
  • Dell Latitude E6230, E6520, E6430 and E6530 (ALPS DualPoint TouchPad), Inspiron N5110 (ALPS GlidePoint), Inspiron 14R Turbo SE7420/SE7520 (ALPS GlidePoint)
  • Samsung NC110/NF210/QX310/QX410/QX510/SF310/SF410/SF510/RF410/RF510/RF710/RV515

如果问题还没有解决,可以手动编译该模块载入内核。

  1. 卸载原有 Alps 触摸板驱动

     pacman -R psmouse-alps-driver
    
  2. 从这里下载:http://www.dahetral.com/public-download
  3. 解压缩,并拷贝至 /usr/src

     tar -xvf alps-xxx.tar
     sudo cp -r usr /
    
  4. 加入编译树,并进行编译

     sudo dkms add psmouse/alps-xxx
     sudo dkms autoinstall
    
  5. 卸载原有模块并载入新的内核模块

     sudo rmmod psmouse || sudo modprobe psmouse
    

上一页 下一页