GDB Debugging Forks

Categories: CPP
show follow-fork-mode Debugger response to a program call of fork or vfork is "parent".set follow-fork-mode mode parent The original process is debugged after a fork. The child process runs unimpeded. This is the default. child The new process is debugged after a fork. The parent process runs unimpeded.show detach-on-fork Whether gdb will detach the child of a fork is on.set detach-on-fork mode on The child process (or parent process, depending on the value of follow-fork-mode) will be detached and allowed to run independently.

Read More →

fork()

Categories: CPP
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <set>#include <sys/wait.h> using namespace std; int main(int argc, char const *argv[]) { int num = 5; set<int> pid_set; int seq = 0; pid_t temp_pid; for (int i=0; i < num; i++) { temp_pid = fork(); if (temp_pid ==0 || temp_pid == -1) break; pid_set.insert(temp_pid); seq++; } if (temp_pid == 0) { for (int j=0; j < 10; j++) { printf("%d---%d---%d\n", getpid(), j, seq); if (seq == 0) { char *p = NULL; printf("%c", *p); } sleep(seq); } return 0; } else { int stat = 0; int ret = 0; while(true){ ret = waitpid(0, &stat, WNOHANG); if (ret > 0) { set<int>::iterator position = pid_set.

Read More →

安装lsyncd

Categories: Linux
1. install Lua5.2 2. install rsync-3.1 3. install lsyncd-2.1.6 2.2.3版本在readhat7.1编译失败 cmake -DCMAKE_C_FLAGS=-ldl . make make install 参考github PS: example文件夹下有配置文件 setting{ statusFile="/tmp/lsyncd.stat", statusInterval = 1, logfile="/var/log/lsyncd-status.log", } sync{ default.rsyncssh, source="/root/zx", targetdir="/root/zx", exclude={'*.csv', '*.log', 'build', 'nbproject'}, host="172.30.241.210", delay=2, rsync = { archive=true, compress=false, whole_file=false, }, ssh = { port=22, --identityFile="/root/.ssh/id_rsa.pub", binary="/usr/bin/ssh", }, } sync{ default.rsyncssh, source="/root/zx", targetdir="/cffex/zx", exclude={'*.swx', '*.swp', '*.csv', '*.log', 'build', 'nbproject'}, host="zhx@172.31.197.10", delay=2, rsync = { --rsh="/usr/bin/ssh -l zhx -i /root/.

Read More →

Linux和Windows换行

Categories: Linux
CRLF: Windows \r\n LF: Unix and OSX \n CR: Classic Mac \r Linux下查看格式: vi filename :set ff 或者 :set fileformat 修改 - sed -i 's/\r//g' filename - sed -i 's/^M//g' filename - vi filename 然后 set ff=unix 保存 PS: 注意\^M在linux下写法,按^M是回车换行符,输入方法是按住CTRL+v,松开v,按m

vmvare multiple network adapters configuration

Categories: Linux
1. add second adapter to virtual machine 2. find out network device name, here is ens33 and ens38 ip a 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:53:2f:a9 brd ff:ff:ff:ff:ff:ff inet 192.168.1.150/24 brd 192.168.1.255 scope global dynamic ens33 valid_lft 27719sec preferred_lft 27719sec inet6 fe80::20c:29ff:fe53:2fa9/64 scope link valid_lft forever preferred_lft forever 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:53:2f:b3 brd ff:ff:ff:ff:ff:ff 3.

Read More →

watchdog

Categories: Linux
The Linux kernel watchdog is used to monitor if a system is running. It is supposed to automatically reboot hanged systems due to unrecoverable software errors. The watchdog module is specific to the hardware or chip being used. Personal computer users don’t need watchdog as they can reset the system manually. However, it is useful for systems that are mission critical and need the ability to reboot themselves without human intervention.

Read More →

常用shell

Categories: Linux
#得到当前脚本路径 script=`readlink -f $0` base_dir=`dirname $script` #循环该目录下所有文件 for exchange in `ls /target/sixreceiver -I mdloader` do done #生成一个uuid cat /proc/sys/kernel/random/uuid #查找不区分大小写的name并拷贝指定目录 find . -iname *config.xml -exec cp '{}' ./zx/zx \; #查看压缩包中文件 tar -vtf package.tar.gz #shell函数 func() { }