linux-errno

错误码分布

  • 1-34 /usr/include/asm-generic/errno-base.h
  • 35-132 /usr/include/asm-generic/errno.h
  • 512-529 /usr/src/linux-headers-$(uname -r)/include/linux/errno.h (大号-内核级别,如系统调用等专用,用户程序一般不可见)
1
2
3
4
5
6
7
8
9
/**
* @file /usr/include/asm-generic/errno-base.h
* @desc 1-34
*/

/**
* @file /usr/include/asm-generic/errno.h
* @desc 35-132
*/

设计模式-参考手册

设计模式六个原则

  • 单一职责原则(Single Responsibility Principle)
  • 开放-封闭原则(Open-Closed Principle)
  • 依赖倒转原则(Dependence Inversion Principle)
  • 里氏代换原则(Liskov Substitution Principle)
  • 迪米特法则(最少知道原则)(Law of Demeter)
  • 合成/聚合复用原则(Composition/Aggregation Principle)

linux c

守护进程

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
pid_t pid = fork();
if (pid < 0)
{
fprintf(stderr, "fork sub process failed!!\n");
return -2;
}
else if (pid > 0)
{
fprintf(stdout, "daemon sub process %d\n", pid);
fprintf(stdout, "logfile %s\n", logfile);
exit(0); // exit this processs [parent/current]
}
else
{
setsid(); // net session and new leader.
my::close_non_std_open_fds(); // close 0,1,2 --
my::close_std_open_fds(); // close all file handle
// sub process run
ret = svc.start(workdir);
char result[2 * 1024] = {0};
sprintf(result, "xx_daemon: workdir=%s, status=%d, pid=%d!\n", workdir, ret, getpid());
syslog(LOG_INFO, result);
// wait to exit!
my::thr_sem exit_sem;
exit_sem.wait(); // no need to exit as a daemon.
svc.stop();
}

new

shell skills

创建目录树

1
mkdir -p {bin,lib,stub,opt,var/{log,tmp,run},devhome,backup,data}

初始化用户目录

1
2
mkdir -p {bin,lib,stub,opt,var/{log,tmp,run},devhome,backup,data};
ln -s var/log log; ln -s var/tmp tmp