0%

本文记录学习的 Linux 命令

dd

快速生成文件

1
2
3
4
5
// 生成 10M 的test文件
$ dd if=/dev/zero of=test bs=1M count=10

// 生成 10K 的test文件
$ dd if=/dev/zero of=test bs=1K count=10

上述命令是实际写入硬盘,文件产生速度取决于硬盘读写速度,如果想要产生超大文件,速度很慢。

阅读全文 »

C 语言中的强制类型转换主要用于基础数据类型之间的转换,语法格式为:

1
2
(type_id) expression
type_id (expression)

C++ 新增了四中强制类型转换:static_cast、const_cast、dynamic_cast、reinterpret_cast
主要用于继承关系类间的强制转换,语法格式为:

1
2
3
4
5
6
7
static_cast<type_id> (expression)
const_cast<type_id> (expression)
dynamic_cast<type_id> (expression)
reinterpret_cast<type_id> (expression)

type_id: 目标数据类型
expression: 原始数据类型变量或者表达式
阅读全文 »

1
2
3
4
5
6
7
8
9
$ wget ftp://ftp.pbone.net/mirror/archive.fedoraproject.org/fedora/linux/updates/13/x86_64/gdb-7.1-34.fc13.x86_64.rpm

$ sudo apt-get install rpm2cpio

$ sudo apt-get install gdb

$ rpm2cpio gdb-7.1-34.fc13.x86_64.rpm | cpio -idmv

$ sudo cp ./usr/bin/gstack /usr/bin/
阅读全文 »

模拟程序:

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
#include <chat_global.hpp>
#include <thread>
#include <chrono>

void func(int i)
{
PRINT_INFO("thread " << i << " start...");
while(1)
{
PRINT_INFO("thread " << i << " run...");
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}

void func_high_cpu()
{
PRINT_INFO("thread high cpu test start...");
while(1)
{

}
}

int main(int argc, char const *argv[])
{
/* code */
std::thread t1(func, 1);

std::thread t2(func, 2);

std::thread t3(func, 3);

std::thread t4(func_high_cpu);

t1.join();
t2.join();
t3.join();
t4.join();

return 0;
}

# 编译时没带 -g 选项
阅读全文 »