linux 生成指定大小文件

linux生成指定大小文件常用的几个命令: fallocate truncate dd head tail fallocate...

2023-08-19 · 1 min · 205 words · Garlic Space

getopt_long

getopt_long可以用来解析命令行参数,也可以进行参数解析。例如 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 #include <stdio.h> /* for printf */ #include <stdlib.h> /* for exit */ #include <getopt.h> static int verbose_flag; int parse(int argc, char **argv) { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"verbose", no_argument, &verbose_flag, 1}, {"add", required_argument, 0, 0 }, {"append", no_argument, 0, 0 }, {"delete", required_argument, 0, 0 }, {"verbose", no_argument, 0, 0 }, {"create", required_argument, 0, 'c'}, {"file", required_argument, 0, 0 }, {0, 0, 0, 0 } }; c = getopt_long(argc, argv, "abc:d:012", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; case '0': case '1': case '2': if (digit_optind != 0 && digit_optind != this_option_optind) printf("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf("option %c\n", c); break; case 'a': printf("option a\n"); break; case 'b': printf("option b\n"); break; case 'c': printf("option c with value '%s'\n", optarg); break; case 'd': printf("option d with value '%s'\n", optarg); break; case '?': break; default: printf("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); } if (verbose_flag) printf ("verbose flag is set\n"); return 0; } void main() { char *argv[6]={0}; int argc = 6; argv[0] = "prog1"; argv[1] = "--add"; argv[2] = "AA"; argv[3] = "-d"; argv[4] = "BB"; argv[5] = "--verbose"; parse(argc, argv); optind = 1; char *argv2[4]={0}; int argc2 = 4; argv2[0] = "prog2"; argv2[1] = "--file"; argv2[2] = "CC"; argv2[3] = "--verbose"; //argv2[3] = "--delete"; //argv2[4] = "DD"; parse(argc2, argv2); return ; } ...

2023-08-09 · 4 min · 831 words · Garlic Space

A kernel debugger in Python: drgn

原文链接:

2023-08-01 · 1 min · 28 words · Garlic Space

leetcode – spiral matrix

问题: Given an m x n matrix, return all elements of the matrix in spiral order.Input: 1 2 3 4 5 array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16 ] ] Output: [1,2,3,4,8,12,11,10,9,5,6,7] 解答: 首先确定行列的边界值, startRow,endRow,startCol,endCol 按照题目的要求进行螺旋便利 , 分别向右, 向下, 向左, 向上移动,对应四个循环。 特殊情况检查, 当出现单行或者单列的情况,在向左或向上遍历前, 分别检查行或列的边界值是否相等, startRow == endRow 或 startCol == endCol , 相等则停止遍历。 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 def spiralTraverse(array): # Write your code here. result = [] startRow , endRow = 0, len(array) - 1 startCol, endCol = 0, len(array[0]) - 1 while startRow <= endRow and startCol <= endCol: # right col for col in range(startCol, endCol + 1): result.append(array[startRow][col]) # down row for row in range(startRow + 1, endRow + 1): result.append(array[row][endCol]) # left col reversed for col in reversed(range(startCol, endCol)): if startRow == endRow: break; result.append(array[endRow][col]) # up row reversed for row in reversed(range(startRow+1, endRow)): if startCol == endCol: break; result.append(array[row][startCol]) startRow = startRow + 1 endRow = endRow -1 startCol = startCol + 1 endCol = endCol - 1 return result ...

2023-07-30 · 1 min · 208 words · Garlic Space

nginx realserver 使用域名方式功能分析

nginx使用域名方式访问RS的一些方案整理:

2023-07-27 · 2 min · 225 words · Garlic Space

SNMP

全称为Simple Network Management Protocol(简单网络管理协议),是一种广泛使用的网络管理协议,允许管理员监视和管理网络设备,如路由器、交换机、服务器和打印机。它是一种应用层协议,促进网络设备与集中的网络管理系统之间的管理信息交换。

2023-06-06 · 4 min · 662 words · Garlic Space

linux sudoers

linux安装完有些系统会默认禁用root登录, 所以我习惯创建一个普通用户然后配置sudoers登录。

2023-05-16 · 2 min · 356 words · Garlic Space

Linux hostname

linux下设置hostname有以下两个命令

2023-05-11 · 2 min · 414 words · Garlic Space

用 flex和bison 解析配置文件

flex和bison是常用的词法分析和语法分析工具, flex可以将源文本以指定个规则识别为单词, bison可以将这些识别出来的单词进行结构化处理。下面可以通过一个bind9 config 解析程序进行说明。 词法分析,语法分析编译过程也是两个过程,通过词法分析, 语法分析, 语义分析前端工作完成输入源代码的识别, 通过中间语言,优化方式完成实现代码可扩展和优化(中端工作), 最终通过生成目标码, 一般也成为后端工作, 实现把源代码变成目标代码的过程。 使用flex和bison可以方便的解析配置文件。就是把字符串分解为token,再将这些token解析到配置文件对应的结构。为之后提供查询修改。 仅简单分析一下包含zone block的bind9配置 识别token bind9.l 标识出要是别的关键字, 也可以过滤掉一些注释和空白字符 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 %{ #include <stdio.h> #include <stdlib.h> #include "y.tab.h" #include "tree.h" %} %% [ \t\r\n]+ /* ignore whitespace*/ "//"(.)*"\n" /* ignore single-line comments */ "/*"(.)*"*/" /* ignore multi-line comments */ "{" { return LBRACE; } "}" { return RBRACE; } ";" { return SEMICOLON; } "=" { return EQUALS; } "zone" { return ZONE; } [a-zA-Z0-9\._/\-]+ { yylval.value = strdup(yytext); return NAME; } \"[^"]*\" { yylval.value = strdup(yytext); return STRING; } %% int yywrap() { return 1; } ...

2023-04-24 · 8 min · 1635 words · Garlic Space

SSL证书与私钥的编码格式和文件扩展名

...

2023-04-09 · 4 min · 712 words · Garlic Space