不积跬步无以至千里


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

Linux学习

发表于 2018-10-27 | 分类于 Linux相关

学习内容

进程的调度和管理

内存的管理

文件系统的管理

设备驱动程序的管理

网络资源的管理

常用命令

1、[功能] 统计文本文件行数

1
wc -l filename

2、[功能] 删除当前目录下除a、b外的文件

1
ls|grep -v 'a\|b'|xargs rm -rf

/proc/$PID/maps文件解读

发表于 2018-10-27 | 分类于 Linux相关

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
2
address           perms offset  dev   inode   pathname
08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm
  • 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.

swap交换分区概念

发表于 2018-10-27 | 分类于 Linux相关

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.

TCP通信-客户端和服务端代码

发表于 2018-10-27 | 分类于 Linux相关

客户端:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <WinSock2.h>

#pragma comment(lib,"ws2_32.lib")

int main()
{
SOCKET soc;
SOCKADDR_IN serverAddr;
SOCKADDR_IN clientAddr;

unsigned char buf[1024];

WSADATA wsa;
WSAStartup(MAKEWORD(1,1),&wsa);

if ((soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) <= 0)
{
printf("create socket fail!\n");
return -1;
}

serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(4999);
serverAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");

if (connect(soc,(SOCKADDR *)&serverAddr,sizeof(serverAddr)) != 0)
{
printf("connect fail!\n");
return -1;
}

while(1)
{
scanf("%s",buf);
if (send(soc,(const char *)buf,strlen((const char *)buf)+1,0) <= 0)
{
printf("Error!\n");
}
}

getchar();
return 0;
}

服务端:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <WinSock2.h>

#pragma comment(lib, "ws2_32.lib")

#include <iostream>
using namespace std;

int main()
{
const int BUF_SIZE = 64;

WSADATA wsd; //WSADATA变量
SOCKET sServer; //服务器套接字
SOCKET sClient; //客户端套接字
SOCKADDR_IN addrServ;; //服务器地址
char buf[BUF_SIZE]; //接收数据缓冲区
char sendBuf[BUF_SIZE];//返回给客户端得数据
int retVal; //返回值

//初始化套结字动态库
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
cout << "WSAStartup failed!" << endl;
return 1;
}
//创建套接字
sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(INVALID_SOCKET == sServer)
{
cout << "socket failed!" << endl;
WSACleanup();//释放套接字资源;
return -1;
}
//服务器套接字地址
addrServ.sin_family = AF_INET;
addrServ.sin_port = htons(4999);
addrServ.sin_addr.s_addr = INADDR_ANY;
//绑定套接字
retVal = bind(sServer, (LPSOCKADDR)&addrServ, sizeof(SOCKADDR_IN));

if(SOCKET_ERROR == retVal)
{
cout << "bind failed!" << endl;
closesocket(sServer); //关闭套接字
WSACleanup(); //释放套接字资源;
return -1;
}
//开始监听
retVal = listen(sServer, 1);
if(SOCKET_ERROR == retVal)
{
cout << "listen failed!" << endl;
closesocket(sServer); //关闭套接字
WSACleanup(); //释放套接字资源;
return -1;
}
//接受客户端请求
sockaddr_in addrClient;
int addrClientlen = sizeof(addrClient);
sClient = accept(sServer,(sockaddr FAR*)&addrClient, &addrClientlen);
if(INVALID_SOCKET == sClient)
{
cout << "accept failed!" << endl;
closesocket(sServer); //关闭套接字
WSACleanup(); //释放套接字资源;
return -1;
}

while(true)
{
//接收客户端数据
ZeroMemory(buf, BUF_SIZE);
retVal = recv(sClient, buf, BUF_SIZE, 0);
if (SOCKET_ERROR == retVal)
{
cout << "recv failed!" << endl;
closesocket(sServer); //关闭套接字
closesocket(sClient); //关闭套接字
WSACleanup(); //释放套接字资源;
return -1;
}
if(buf[0] == '0')
break;
cout << "客户端发送的数据: " << buf <<endl;
cout << "向客户端发送数据: " ;
cin >> sendBuf;
send(sClient, sendBuf, strlen(sendBuf), 0);
}

//退出
closesocket(sServer); //关闭套接字
closesocket(sClient); //关闭套接字
WSACleanup(); //释放套接字资源;

return 0;
}

git命令

发表于 2018-10-26 | 分类于 版本控制

git工作流示意图

git clone

远程操作的第一步,通常是从远程主机克隆一个版本库,这时就要用到git clone命令。

1
$ git clone <版本库的网址>

比如:

1
$ git clone git@github.com:cgc0415/hello-world.git

该命令会在本地主机生成一个目录,与远程主机的版本库同名。如果要指定不同的目录名,可以将目录名作为git clone命令的第二个参数。

1
$ git clone <版本库的网址> <本地目录名>

git remote

为了便于管理,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

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 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回车换行设置】—避免Windows自动将Linux的换行符转为Windows风格,造成文件二进制不一致

执行git config –list,查看所有设置
确保 core.autocrlf=false
如果不是则用如下命令修改:
git config –global core.autocrlf false

修改文件名

1
2
git mv originfilename changed_filename
git commit -m ""

删除文件或文件夹

删除文件

1
git rm filename

删除foldername文件夹及其下所有的文件

1
git rm foldername -r -f

执行完git rm后,最后再git commit -m “”,然后push即可

stash的使用

有时候我们在工作区进行开发并且不想提交的时候,这时我们又想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

git-rebase

当从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次提交已被合并为一个。

修改commit信息

有时候我们执行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

【git clean】删除untracked files

1
git clean -f

linux手册中函数名后小括号中数字的含义

发表于 2018-10-26 | 分类于 Linux相关

It’s the section that the man page for the command is assigned to.

  1. General commands

  2. System calls

  3. C library functions

  4. Special files (usually devices, those found in /dev) and drivers

  5. File formats and conventions

  6. Games and screensavers

  7. Miscellanea

  8. System administration commands and daemons

Original descriptions of each section can be seen in the Unix Programmer’s Manual (page ii).

首次使用Github

发表于 2018-10-25 | 分类于 版本控制

1、配置用户名和邮箱

2、创建SSH-KEY

然后系统提示输入文件保存位置等信息,连续敲三次回车即可
如果一切顺利的话,可以在用户主目录里找到.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

3、添加SSH-KEY到github

然后用文本编辑工具打开该公钥文件,使用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密码

4、验证SSH-KEY是否生效

验证SSH-KEY是否添加成功:

看到You’ve successfully authenticated,则表示SSH-KEY已添加成功并生效!

魔方_CFOP教程

发表于 2018-10-24

魔方的公式说明

魔方的某个面

整个魔方

魔方双层转

中间层

OLL公式

PLL公式

Windows Ping加时间戳

发表于 2018-10-21

在c盘下面新建文件 ping.vbs,在 ping.vbs中输入代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Dim args, flag, unsuccOut
args=""
otherout=""
flag=0

If WScript.Arguments.count = 0 Then
WScript.Echo "Usage: cscript tping.vbs [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]"
WScript.Echo " [-s count] [[-j host-list] | [-k host-list]]"
WScript.Echo " [-r count] [-w timeout] destination-list"
wscript.quit
End if

For i=0 to WScript.Arguments.count - 1
args=args & " " & WScript.Arguments(i)
Next

Set shell = WScript.CreateObject("WScript.Shell")
Set re=New RegExp
re.Pattern="^Reply|^Request|^来自|^请求"

Set myping=shell.Exec("ping" & args)

while Not myping.StdOut.AtEndOfStream
strLine=myping.StdOut.ReadLine()
'WScript.Echo "原数据" & chr(9) & strLine
r=re.Test(strLine)
If r Then
WScript.Echo date & " "& time & chr(9) & strLine
flag=1
Else
unsuccOut=unsuccOut & strLine
End if
Wend

if flag = 0 then
WScript.Echo unsuccOut
end if

切到脚本所在目录,然后调出cmd,执行如下命令:

1
cscript ping.vbs www.baidu.com -t -l 1000 -w 5000>sseping.txt

Office常见问题及解决方法

发表于 2018-10-21 | 分类于 工具安装及使用

OneNote

1、OneNote粘贴的图片比较模糊

问题原因:Microsoft为了使OneNote排版美观,在粘贴一些尺寸较大的图片时,会将图片进行缩放。
解决方法:右键->还原为原始尺寸

Excel

1、对一列应用同一个公式

方法:鼠标移动到第一个单元格的右下角,变成十字架后,双击鼠标

2、分屏显示两个excel表格

方法:每次都从开始菜单找到Excel,单独打开文件,就可以把每个文件放到单独的窗口中分屏显示了

123

cgc0415

24 日志
8 分类
20 标签
© 2019 cgc0415
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4