学习内容
进程的调度和管理
内存的管理
文件系统的管理
设备驱动程序的管理
网络资源的管理
常用命令
1、[功能] 统计文本文件行数
1 | wc -l filename |
2、[功能] 删除当前目录下除a、b外的文件
1 | ls|grep -v 'a\|b'|xargs rm -rf |
Each row in /proc/$PID/maps describes a region of contiguous virtual memory in a process or thread. Each row has the following fields:
1 | address perms offset dev inode pathname |
- address - This is the starting and ending address of the region in the process’s address space
- permissions - This describes how pages in the region can be accessed. There are four different permissions: read, write, execute, and shared. If read/write/execute are disabled, a ‘-‘ will appear instead of the ‘r’/‘w’/‘x’. If a region is not shared, it is private, so a ‘p’ will appear instead of an ‘s’. If the process attempts to access memory in a way that is not permitted, a segmentation fault is generated. Permissions can be changed using the mprotect system call.
- offset - If the region was mapped from a file (using mmap), this is the offset in the file where the mapping begins. If the memory was not mapped from a file, it’s just 0.
- device - If the region was mapped from a file, this is the major and minor device number (in hex) where the file lives.
- inode - If the region was mapped from a file, this is the file number.
- pathname - If the region was mapped from a file, this is the name of the file. This field is blank for anonymous mapped regions. There are also special regions with names like [heap], [stack], or [vdso]. [vdso] stands for virtual dynamic shared object. It’s used by system calls to switch to kernel mode.
You might notice a lot of anonymous regions. These are usually created by mmap
but are not attached to any file. They are used for a lot of miscellaneous things like shared memory or buffers not allocated on the heap. For instance, I think the pthread library uses anonymous mapped regions as stacks for new threads.
Linux divides its physical RAM (random access memory) into chucks of memory called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.
1 | #include <stdio.h> |
1 | #include <stdio.h> |
远程操作的第一步,通常是从远程主机克隆一个版本库,这时就要用到git clone
命令。1
$ git clone <版本库的网址>
比如:1
$ git clone git@github.com:cgc0415/hello-world.git
该命令会在本地主机生成一个目录,与远程主机的版本库同名。如果要指定不同的目录名,可以将目录名作为git clone
命令的第二个参数。1
$ git clone <版本库的网址> <本地目录名>
为了便于管理,Git要求每个远程主机都必须指定一个主机名。git remote
命令就用于管理主机名。
不带选项的时候,git remote
命令列出所有远程主机。1
2$ git remote
origin
使用-v
选项,可以参看远程主机的网址。1
2
3$ git remote -v
origin git@github.com:cgc0415/hello-world.git (fetch)
origin git@github.com:cgc0415/hello-world.git (push)
上面命令表示,当前只有一台远程主机,叫做origin,以及它的网址。
git pull
命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并。它的完整格式稍稍有点复杂。
1 | $ git pull <远程主机名> <远程分支名>:<本地分支名> |
比如,取回origin
主机的next
分支,与本地的master
分支合并,需要写成下面这样。1
$ git pull origin next:master
在某些场合,Git会自动在本地分支与远程分支之间,建立一种追踪关系(tracking)。比如,在git clone
的时候,所有本地分支默认与远程主机的同名分支,建立追踪关系,也就是说,本地的master
分支自动”追踪”origin/master
分支。
如果当前分支与远程分支存在追踪关系,且远端只有一个追踪分支,则直接执行git pull
就可以。
1 | $ git pull |
上面命令表示,当前分支自动与唯一一个追踪分支进行合并。
git push
命令用于将本地分支的更新,推送到远程主机。它的格式与git pull
命令相仿。
1 | $ git push <远程主机名> <本地分支名>:<远程分支名> |
如果省略远程分支名,则表示将本地分支推送到与之存在”追踪关系”的远程分支(通常两者同名),如果该远程分支不存在,则会被新建。1
$ git push origin master
上面命令表示,将本地的master分支推送到origin主机的master分支。如果后者不存在,则会被新建。
如果省略本地分支名,则表示删除指定的远程分支,因为这等同于推送一个空的本地分支到远程分支。1
2
3$ git push origin :master
# 等同于
$ git push origin --delete master
上面命令表示删除origin主机的master分支。
如果远程主机的版本比本地版本更新,推送时Git会报错,要求先在本地做git pull
合并差异,然后再推送到远程主机。这时,如果你一定要推送,可以使用--force
选项。1
$ git push --force origin master
上面命令使用--force
选项,结果导致远程主机上更新的版本被覆盖。除非你很确定要这样做,否则应该尽量避免使用--force
选项。
执行git config –list,查看所有设置
确保 core.autocrlf=false
如果不是则用如下命令修改:
git config –global core.autocrlf false
1 | git mv originfilename changed_filename |
删除文件1
git rm filename
删除foldername文件夹及其下所有的文件1
git rm foldername -r -f
执行完git rm后,最后再git commit -m “”,然后push即可
有时候我们在工作区进行开发并且不想提交的时候,这时我们又想pull最新代码;或者又想切到另外一个分支上修改紧急bug的时候
git stash可以暂存当前的工作区内容:
1 | git stash save "stash information." |
等我们切到另外分支修改完了bug之后,可以切回之前分支【一定要先切回原分支再执行下面的pop或apply命令】,然后恢复之前工作区的内容继续开发:1
git stash pop
也可以查看stash的Git栈信息:1
git stash list
当我们的stash栈列表里面有很多,并且我们想要找到对应的版本号并且将我们想要的版本号为stash@{2}的工作内容取出来:1
git stash apply stash@{2}
也可以查看版本号为stash@{2}的工作内容:1
git stash show stash@{2}
可以将栈清空:1
git stash clear
1 | git show commit-id filename |
1 | git reflog show --date=iso branchname |
当从master拉完分支,修改后,发现需要合入master分支上最新的commit时,可以先提交该分支上的修改,然后checkout到master上,git pull到最新,然后切回分支,执行 git rebase master 即可。
在进行rebase操作时,可能会遇到文件存在冲突的情况,这时git会显示出存在冲突的(CONFLICT)文件名,可以用beyondcompare进行比较,手动解决冲突后,再用git add来标识该文件冲突已解决,当冲突解决后再执行git rebase –continue即可。
(1)、git rebase -i HEAD~2(合并最近2次commit)
(2)、执行完1后,即进入commit信息编辑界面,在这里将第一次提交改为pick,第2次提交改为squash,意思就是将第二次提交合并到第一次提交上。编辑完后输入:wq保存退出,即进入步骤3。
(3)、在第2步执行完后即进入注释修改界面,可以将第2次commit信息删除,将第1次commit信息修改为想要的内容,之后输入:wq保存并退出。
(4)、使用git log查看最近commit记录,发现最近2次提交已被合并为一个。
有时候我们执行git commit
命令提交完了才发现漏掉了几个文件没有加,或者提交信息写错了。想要撤消刚才的提交操作,可以使用--amend
选项重新提交:1
2
3$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend -m "the correct commit."
在initial commit
之后,如果没有文件修改遗漏,只是需要修改提交信息的话,直接跳到git commit --amend -m "the correct commit."
即可。
1 | git reset --hard commitid |
1 | git clean -f |
It’s the section that the man page for the command is assigned to.
General commands
System calls
C library functions
Special files (usually devices, those found in /dev) and drivers
File formats and conventions
Games and screensavers
Miscellanea
System administration commands and daemons
Original descriptions of each section can be seen in the Unix Programmer’s Manual (page ii).
然后系统提示输入文件保存位置等信息,连续敲三次回车即可
如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
- Linux下生成的SSH key文件保存在中~/.ssh/id_rsa.pub
- Windows下保存在C:\Users\lzw.ssh
然后用文本编辑工具打开该公钥文件,使用notepad++或者sublime。不要使用记事本打开,因为记事本的默认编码不是utf-8,拷贝里面的全部内容,将它粘帖到github帐号管理中的添加SSH key界面中。
打开github帐号管理中的添加SSH key界面的步骤如下:
1、登录github
2、点击右上方的Accounting settings图标
3、选择 SSH key
4、点击 Add SSH key
在出现的界面中填写SSH key的名称,填一个你自己喜欢的名称即可,然后将上面拷贝的~/.ssh/id_rsa.pub文件内容粘帖到key一栏,在点击“add key”按钮就可以了。
添加过程github会提示你输入一次你的github密码
验证SSH-KEY是否添加成功:
看到You’ve successfully authenticated,则表示SSH-KEY已添加成功并生效!
1 | Dim args, flag, unsuccOut |
1 | cscript ping.vbs www.baidu.com -t -l 1000 -w 5000>sseping.txt |