Linux嵌入式由于诸多的限制,调试方法有限,常常出现面对Bug束手无策的情况,现在介绍一种通过信号处理对Linux嵌入式应用程序进行调试的方法。

linux中一共有32种信号,在/usr/include/bits/signum.h 头文件中可以看到,具体如下:SIGHUP ;SIGINT ;SIGQUIT ;SIGILL ;SIGTRAP ;SIGABRT ;SIGIOT ;SIGBUS ;SIGFPE ;SIGKILL ;SIGUSR1 ;SIGSEGV ;SIGUSR2 ;SIGPIPE ;SIGALRM ;SIGTERM ;SIGSTKFLT ;SIGCLD ;SIGCHLD ;SIGCONT ;SIGSTOP ;SIGTSTP ;SIGTTIN ;SIGTTOU ;SIGURG ;SIGXCPU ;SIGXFSZ ;SIGVTALRM ;SIGPROF ;SIGWINCH ;SIGPOLL ;SIGIO ;SIGPWR ;SIGSYS ;SIGUNUSED
以上来自:https://blog.csdn.net/u010133805/article/details/53899667 ,他用的c++,改成c研究研究,如下:

看编号,用kill -l,SIGUSR1编号为10,如下所示:
#kill -l
1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

其中SIGUSER1信号用户可以自己定义其处理行为,处理范例如下:

#make usr1
cc     usr1.c   -o usr1
./usr1

ps -ef|grep usr1

kill -s SIGUSR1 17331
sig_num=10
flag is true!
sig_num=10
flag is false
flag is false
macbook鼠标慢命令行设置:
defaults read -g com.apple.mouse.scaling
defaults write -g com.apple.mouse.scaling 10.0




MAC下截屏命令是Command+Shift+3,部分截屏命令是Command+Shift+4。
---------
按下Command+Shift+4并按下空格键。 交叉十字图标将变为小照相机图标。
你可以再次按下空格键转换为交叉十字图标。
移动光标到你希望进行截图的窗口上。
当照相机图标移过不同窗口上时,窗口将程高亮蓝色显示。 ...
点击所需窗口。 和其他截图方法一样,所选窗口的截图将默认保存在桌面上。


MAC下退出VIrtualBox全屏命令是Command+C,鼠标退出来的命令是command.




snip快捷键和钉钉的截图快捷键冲突,需要将钉钉的截图删除掉。
钉钉-》偏好设置-》快捷键里修改或者删掉。
我用的是微信的截图,不一定登录上,只要打开就能截图,微信-设置-快捷键如下:
Control+Command+a。AddTime:2023-05-14.

应用界面居中control+option+command+C


vim ~/.zshrc
# export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/.irdcops/shell/tools/location.jackxiang.com:$PATH
export PATH=$HOME/.irdcops/shell/tools/ippbcopy.jackxiang.com:$PATH

Mac终端被自己玩“坏”了,登陆默认是-bash-3.2$,一些命令无法使用,现在记录恢复初始化    [username(你的账户名)@主机名 ~] $   解决的办法。
工具/原料
Mac
终端
方法/步骤1
终端输入以下命令:

export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin

之后输入

cd ~/

3、先输入

touch .bash_profile

之后输入

open .bash_profile

打开文件之后,在文件的最后一行添加

export PS1='[\u@\h \w]\$'



之后按住保存该文件关闭

输入下列命令,刷新终端,ok~

source .bash_profile

补充:关于更改主机名和共享名

主机名

sudo scutil --set HostName rainbird-desk

共享名

sudo scutil --set ComputerName newName


来自:https://jingyan.baidu.com/article/c74d6000c277e80f6a595d8c.html



二)MAC 设置环境变量PATH 和 查看PATH
理论篇
Mac系统的环境变量,加载顺序为:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc

#中间用冒号隔开
export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>

实践主要是:ckubectlcmd    ckubectlishow 两个快捷命令,如下:
$cat /Users/jackXiang/.bashrc |grep kube


$cat /Users/jackXiang/.bash_profile

参考自:https://www.jianshu.com/p/acb1f062a925
法一)直接PKG安装:
#pkg install git
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB 118.7kB/s    00:57    
Processing entries: 100%
FreeBSD repository update completed. 32579 packages processed.
All repositories are up to date.
Updating database digests format: 100%
The following 15 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        git: 2.19.1
        p5-CGI: 4.40
        p5-HTML-Parser: 3.72
        p5-HTML-Tagset: 3.20_1
        perl5.24: 5.24.4
        p5-IO-Socket-SSL: 2.059

法二)Ports源码安装:

cd /usr/ports/devel/git
sudo make install clean BATCH="yes"

https://www.digitalocean.com/community/tutorials/how-to-install-git-on-freebsd-11-0






sudo pkg update
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD has a wrong packagesite, need to re-create database

Fetching meta.conf: 100%    163 B   0.2kB/s    00:01    
Fetching packagesite.pkg: 100%    7 MiB  73.4kB/s    01:41    
Processing entries:   0%
Newer FreeBSD version for package zziplib:
To ignore this error set IGNORE_OSVERSION=yes
- package: 1302001
- running kernel: 1300139
Ignore the mismatch and continue? [y/N]: pkg: repository FreeBSD contains packages for wrong OS version: FreeBSD:13:amd64
Processing entries: 100%
Unable to update repository FreeBSD
Error updating repositories!
========================================================

根据错误信息,您遇到了一个由于系统版本不匹配而导致的问题。您的系统内核版本是`1300139`,而存储库中的软件包适用于版本`1302001`。以下是解决此问题的步骤:

1. **确认系统版本:**
   使用以下命令确认您的系统版本:

    ```bash
    uname -a
    ```

   如果输出的版本与错误中提到的不匹配,您可能需要更新系统。

2. **更新系统:**
   如果系统版本不匹配,尝试更新系统以匹配存储库中的软件包版本。使用以下命令:

    ```bash
    freebsd-update fetch install
    ```

   这将尝试将您的系统更新到最新的稳定版本。

3. **更新软件包数据库:**
   更新软件包数据库,以确保它与新的系统版本兼容:

    ```bash
    sudo pkg update
    ```

   如果这仍然失败,您可能需要重新创建软件包数据库。

4. **重新创建软件包数据库:**
   执行以下命令来重新创建软件包数据库:

    ```bash
    sudo pkg bootstrap -f
    ```

   然后再次运行更新命令:

    ```bash
    sudo pkg update
    ```

   现在,您应该能够更新软件包并安装Git。

请注意,由于系统版本不匹配可能会导致其他依赖关系问题,如果遇到其他错误,请根据错误消息逐个解决。如果有其他问题或需要更多帮助,请告诉我。
问题: sh: zip: not found

Port安装:
cd /usr/ports/archivers/zip/ && make install clean

安装后位置: /usr/local/bin/zip
#systemctl stop slapd
Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)
解决这个问题:
第一步)主要是重装  polkit,然后重启。
#rpm -qa|grep polkit
polkit-0.112-14.el7.x86_64
polkit-pkla-compat-0.1-4.el7.x86_64
来自:https://blog.csdn.net/wuyezhiyu/article/details/82905661

弟二步)#systemctl start dbus.service
Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)

#ps -ef|grep dbus
root     31670     1  0 09:38 ?        00:00:00 [dbus-daemon] <defunct>

#systemctl list-unit-files|grep dbus.service        #查看systemd管理的所有单元
dbus.service                 static  
systemctl enable dubs.service        

access("/etc/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/run/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/lib/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/usr/lib/systemd/system/dubs.service", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/rc.d/init.d/dubs", F_OK)   = -1 ENOENT (No such file or directory)
"static"  尚未被启用,并且单元文件的 "[Install]" 小节中没有可用于 enable 命令的选项
"disabled"  尚未被启用,但是单元文件的 "[Install]" 小节中存在可用于 enable 命令的选项
"enabled"  已经通过 /etc/systemd/system/ 目录下的 Alias= 别名、 .wants/ 或 .requires/ 软连接被永久启用

来自:https://mellowhost.com/billing/index.php?rp=/knowledgebase/71/Error-getting-authority-Error-initializing-authority-Could-not-connect-Connection-refused-g-io-error-quark-39.html


Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)
systemctl stop slapd
Error getting authority: Error initializing authority: Could not connect: Connection refused (g-io-error-quark, 39)

在使用centos7.4 安装服务的时候报错:

Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)
解决方案:


ps -ef |grep polkit

再安装:
pyum reinstall polkit

再重启
reboot

就可以解决

来自:http://www.cnblogs.com/flyfish2012/p/9527810.html
背景:在Docker打包PHP时发现这个命令,于是查了一下。
strip命令用于脱掉文件的衣服, 文件会变小, 其中的符号信息会失去。 那这个strip有什么

用呢? 很有用的! 原来的a.out比较大, 可以执行。 在strip之后, 文件变小了, 也是可以执行, 这就节省了很多空间.

      其实, strip不仅仅可以针对可执行文件, 还能针对目标文件和动态库等. 在实际的开发中, 经常需要对动态库.so进行strip操作, 减少占地空间。 而在调试的时候(比如用addr2line), 就需要符号了。 因此, 通常的做法是: strip前的库用来调试, strip后的库用来实际发布, 他们两者有对应关系。 一旦发布的strip后的库出了问题, 就可以找对应的未strip的库来定位。

      例如某个动态库strip前是50M左右, strip后是20M左右, 可见, 脱脱衣服还是有明显好处的。

      我们在调试过程中, 经常涉及到上传库, 库太大时, 很耗费传输时间, 所以还是先用strip来处理一下比较好。
---------------------
/data/codesdev/testdemo/c/strip]
#tree -l
.
├── strip
└── strip.c

#cat strip.c
#include <stdio.h>  

void main()  
{  
    printf("strip\n");
}

#make strip
cc     strip.c   -o strip

#ls -l strip
-rwxr-xr-x 1 root root 8440 11月  1 17:26 strip

#/usr/bin/file strip
strip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ec884c4b45d605867f9319a6d5b3acaea1866798, not stripped

#nm strip
000000000060102c B __bss_start
000000000060102c b completed.6355
0000000000601028 D __data_start
0000000000601028 W data_start
0000000000400460 t deregister_tm_clones

#strip strip

#ls -l strip  #File Size变小
-rwxr-xr-x 1 root root 6296 11月  1 17:28 strip

#file strip
strip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ec884c4b45d605867f9319a6d5b3acaea1866798, stripped

#nm strip
nm: strip:无符号


来自:https://blog.csdn.net/qq_37858386/article/details/78559490
freebsd-update -r 11.2-RELEASE upgrade
/usr/sbin/freebsd-update install
中间有几次NTP的配置文件确认。
/usr/sbin/freebsd-update install
reboot


FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
Welcome to jackxiang's Compute Service !

参考:https://blog.csdn.net/joyous/article/details/81990019


升级遇到的问题,出现openssl的动态链接库版本对不上。
最后一次构建FreeBSD镜像::
1)无法再次升级,原因是相关SSHD和Mysqld的动态链接libssl会有问题。

2)FreeBSD升级到11.3还会出sockstat -4l会报错。

3)即使到FreeBSD12.0后Mysql编译好的启动可能也有问题,由于旧的库可能还是涉及到libssl还是有问题。

最终,无法升级,做了一些域名应用快捷方面的优化以及完善了PHP扩展,得出这个版本是一个最后的ISO版本FreeBSD11.2。

pkg info -r security/openssl
openssl-1.0.2l,1:
        libarchive-3.3.1,1
        mysql80-client-8.0.0_3
        bind-tools-9.11.1P3
pkg auto remove
pkg upgrade -y
rm -rf /var/db/freebsd-update/files  #记得删掉。


一些其它命令:
> pkg-add -r openssh-portable
> cd /usr/ports / security / openssh&& make install clean


> portupgrade security / openssh-portable
> makeworld / buildworld过程的一部分
> freebsd-upgrade
1.CURL批量:

输出(注意那个双引号里加一个单引号引起来,输出单引号,还是那个双引号为匹配,里面单引号原样输出,这点得记住!):
/usr/bin/curl -I 'baidu.com'
/usr/bin/curl -I '360.cn'
/usr/bin/curl -I 'souhu.com'
/usr/bin/curl -I 'sina.com.cn'

for i in $(cat url.txt);do echo /usr/bin/curl -I "''$i'''";done;  #双引号里加一个单引号引起来,输出单引号,还是那个双引号为匹配
/usr/bin/curl -I ''baidu.com'''
/usr/bin/curl -I ''360.cn'''
/usr/bin/curl -I ''souhu.com'''
/usr/bin/curl -I ''sina.com.cn'''

Curl命令实战:

;done;    
curl: (6) Couldn't resolve host ''baidu.com''
curl: (6) Couldn't resolve host ''360.cn''
curl: (6) Couldn't resolve host ''souhu.com''
curl: (6) Couldn't resolve host ''sina.com.cn''

2.Nc批量:

nc -w 1 -z -v 10.71.182.175 80
nc -w 1 -z -v 192.168.111.43 80

for i in $(cat ip.txt);do  nc -w 1 -z -v $i 80;done;  
Connection to 10.71.182.175 80 port [tcp/http] succeeded!
Connection to 192.168.111.43 80 port [tcp/http] succeeded!
strings
ldd
autoconf
yum groupinstall "Development Tools"
sudo fstat -p 42477 | grep my.cnf 打开后关掉了,无法找到。
cat /usr/local/etc/rc.d/mysql-server |grep my.cnf
#                       ${mysql_confdir}/my.cnf if it exists.
if [ -f "${mysql_confdir}/my.cnf" ]; then
: ${mysql_optfile="${mysql_confdir}/my.cnf"}
elif [ -f "${mysql_dbdir}/my.cnf" ]; then
: ${mysql_optfile="${mysql_dbdir}/my.cnf"}

sh  -x /usr/local/etc/rc.d/mysql-server  start //于是直接-x找my.cnf
+ : /usr/local/etc/mysql
+ [ -f /usr/local/etc/mysql/my.cnf ]
+ [ -f /var/db/mysql/my.cnf ]
ls /etc/mysql/my.cnf /etc/my.cnf /usr/local/mysql/my.cnf /usr/local/etc/my.cnf /usr/local/etc/mysql/my.cnf /var/db/mysql/my.cnf


ps -eo pid,ppid,pgrp,session,comm --forest|less      # Linux上使用,Macbook: brew install pstree ,用pstree

ps -eo pid,ppid,pgrp,session,comm|grep -E '(Google\ Chrome|chrome)'

一)基础命令:删目录前看是否有进程打开了目录里的文件之lsof命令。
lsof -c abc 显示abc进程现在打开的文件
lsof -p  列出进程号为1234的进程所打开的文件
lsof -c java  #实践成功
lsof  -p  51640  #实践成功
lsof -g gid 显示归属gid的进程情况
lsof -g 0|grep zcms-0103
lsof  app-2020-08-05.log    #lsof abc.txt 显示开启文件abc.txt的进程
lsof  -d 4 #lsof -d 4 显示使用fd为4的进程,每个进程PID里都是从0,1,2,3,4开始的,出来的有4的所有进程列表。
lsof abc.txt 显示开启文件abc.txt的进程
来自:https://blog.csdn.net/weixin_34019929/article/details/92364579

二)常用想删目录时查看进程是否打开并在访问:
lsof +d /usr/local/ 显示目录下被进程开启的文件
lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长

lsof +d /data/www/zcms3x/zcms-0103
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oosplash  49169 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103
soffice.b 49188 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103

lsof +D /data/www/zcms3x/zcms-0103
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oosplash  49169 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103
soffice.b 49188 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103


kubectl exec stress-pod -- ps -o "rss,vsz,comm"|grep -v VSZ
2576 6256 stress-ng
3628 6900 stress-ng-cpu
  64 6256 stress-ng-vm
135m 262m stress-ng-vm
   4 1504 ps

rss: 物理
vsz: 虚拟
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)

背景:在多进程时,用那个叫物理内存、虚拟内存的,怎么看?https://blog.csdn.net/i_am_jojo/article/details/7862362

ps -eo pid,ppid,gid,sid,tty,cmd --forest|less


  -e     Select all processes.  Identical to -A.
  -o format
              User-defined format.  format is a single argument in the form of a blank-separated or comma-separated
              list, which offers a way to specify individual output columns.  The recognized keywords are described
              in the STANDARD FORMAT SPECIFIERS section below.  Headers may be renamed (ps -o pid,ruser=RealUser -o
              comm=Command) as desired.  If all column headers are empty (ps -o pid= -o comm=) then the header line
              will not be output.  Column width will increase as needed for wide headers; this may be used to widen
              up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).  Explicit width control (ps opid,
              wchan:42,cmd) is offered too.  The behavior of ps -o pid=X,comm=Y varies with personality; output may
              be one column named "X,comm=Y" or two columns named "X" and "Y".  Use multiple -o options when in
              doubt.  Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are
              macros that may be used to choose the default UNIX or BSD columns.

       -C cmdlist
              Select by command name.  This selects the processes whose executable name is given in cmdlist.
       --forest
              ASCII art process tree.

#ps -eo 'pid,ppid,gid,sid,tty,cmd' |grep Easy
26721 62388     0 62388 pts/4    EasySwoole
26722 26721     0 62388 pts/4    EasySwoole
26744 26722     0 62388 pts/4    EasySwoole.Crontab
31311 26722     0 62388 pts/4    EasySwoole.Worker.0
31312 26722     0 62388 pts/4    EasySwoole.Worker.1
31313 26722     0 62388 pts/4    EasySwoole.Worker.2
31314 26722     0 62388 pts/4    EasySwoole.Worker.3
31315 26722     0 62388 pts/4    EasySwoole.Worker.4
31316 26722     0 62388 pts/4    EasySwoole.Worker.5
31317 26722     0 62388 pts/4    EasySwoole.Worker.6
31318 26722     0 62388 pts/4    EasySwoole.Worker.7
31319 26722     0 62388 pts/4    EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4    EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4    EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4    EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4    EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4    EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4    EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4    EasySwoole.TaskWorker.15

对Crontab进行查看:
lsof -nPp 26744|grep swoole.log
php     26744 root   11u      REG              253,0  39874179 100744037 /data/logs/php/swoole.lo

#lsof -nPp 26721 |grep LISTEN
php     26721 root    3u     IPv4             763966       0t0       TCP *:8080 (LISTEN)
php     26721 root   10u     IPv4             762762       0t0       TCP 127.0.0.1:9000 (LISTEN)


26721 62388     0 62388 pts/4         \_ EasySwoole
26722 26721     0 62388 pts/4             \_ EasySwoole
26742 26722     0 62388 pts/4                 \_ HotReload
26743 26722     0 62388 pts/4                 \_ KafkaAddFormId
26744 26722     0 62388 pts/4                 \_ EasySwoole.Crontab
31311 26722     0 62388 pts/4                 \_ EasySwoole.Worker.0
31312 26722     0 62388 pts/4                 \_ EasySwoole.Worker.1
31313 26722     0 62388 pts/4                 \_ EasySwoole.Worker.2
31314 26722     0 62388 pts/4                 \_ EasySwoole.Worker.3
31315 26722     0 62388 pts/4                 \_ EasySwoole.Worker.4
31316 26722     0 62388 pts/4                 \_ EasySwoole.Worker.5
31317 26722     0 62388 pts/4                 \_ EasySwoole.Worker.6
31318 26722     0 62388 pts/4                 \_ EasySwoole.Worker.7
31319 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.15

ps --headers -eo pid,ppid,GID,tty,sid,vsz,rss,cmd -C EasySwoole


To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm

Print only the process IDs of syslogd:
          ps -C syslogd -o pid=

相查看树,能看到进程的继承关系:
ps -eo 'pid,ppid,vsz,rss,cmd' --forest
3078  1214  48620  3032  \_ sshd: xiangdong [priv]
3084  3078  48752  1680      \_ sshd: xiangdong@pts/0,pts/1,pts/2
3085  3084 108352  1788          \_ -bash
3644  3085 189592  2940          |   \_ sudo su -
3645  3644 163756  1964          |       \_ su -
3646  3645 108476  1908          |           \_ -bash
5416  3646 108412  1200          |               \_ ps -eo pid,ppid,vsz,rss,cmd --forest
5417  3646 105460   816          |               \_ less

1481     1  55604  1460 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
1484  1481  76816 22864  \_ nginx: worker process                                          
1485  1481  76816 22936  \_ nginx: worker process                                          
1486  1481  76816 22936  \_ nginx: worker process                                          
1487  1481  76816 22936  \_ nginx: worker process  


cat pod-test.yml    



PHP连接未释放之lsof -d 5|grep 2654实现反debug程序PID里的fd对应的tcp连接句柄:
原文,以下是学习到的点:php curl连接未释放,strace结果:poll([{fd=5, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 1000) = 0 (Timeout)
https://www.jianshu.com/p/8a247cae629a
Nc服务端:
[root@golang_server_10_10_0_44:/usr/local/src/go-sftp]
#nc -l 1234
GET / HTTP/1.1
User-Agent: curl/7.29.0
Host: 10.10.0.44:1234
Accept: */*

Client连接端:
[root@swoole_server_10_10_0_45:~]
#ps -ef|grep curl
root      9055  9012  0 03:57 pts/1    00:00:00 curl 10.10.0.44:1234
#curl 10.10.0.44:1234
#ls /proc/9055/fd
0  1  2  3

[root@swoole_server_10_10_0_45:~]
#lsof  -d 3|grep 9055
curl       9055      root    3u     IPv4           23202662      0t0       TCP wx.levoo.com:41490->localhost:search-agent (ESTABLISHED)

#strace -f -p 9055
strace: Process 9055 attached
restart_syscall(<... resuming interrupted poll ...>) = 0
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000


设置超时后呢?
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 987)   = 0 (Timeout)会提示:
curl: (28) Operation timed out after 20001 milliseconds with 0 out of -1 bytes received


#curl 10.10.0.44:1234 --connect-timeout 10 -m 20
curl: (28) Operation timed out after 20001 milliseconds with 0 out of -1 bytes received



man lsof
       -d s     specifies a list of file descriptors (FDs) to exclude from or include in the output listing.  The file descriptors are  specified  in
                the comma-separated set s - e.g., ``cwd,1,3'', ``^6,^2''.  (There should be no spaces in the set.)
lsof  -nPp 57700|grep cwd
nginx   57700 root  cwd    DIR             253,16     4096   47185921 /data/www
lsof  -nPp 33441|grep cwd
java    33441 root  cwd    DIR              104,3     4096  2757893 /data/xxxxrsync
ls /proc/33441/cwd/  #/data/xxxxrsync的目录的东西
函数说明:chdir()用户将当前的工作目录改变成以参数路径所指的目录。


连接超时时间用 --connect-timeout 参数来指定,数据传输的最大允许时间用 -m 参数来指定。

一直Poll的解决办法:php curl调用时设置超时
libcurl中同一时候封装了select以及poll这两种I/O机制。
代码中使用宏HAVE_POLL_FINE对这两者进行分离。假设定义了这个宏,则使用poll,否则使用select。
libcurl中同一时候封装了select以及poll这两种I/O机制。
代码中使用宏HAVE_POLL_FINE对这两者进行分离。假设定义了这个宏,则使用poll,否则使用select。
这两者的使用代码都位于函数curl_poll()中,而此函数定义在文件lib/select.c中。我看默认是poll的模式。

Curl不设置超时,对nc -l 1234进行访问会一直不退出的,一直 poll的,刚才实践的确如此,一般都要加上超时参数,如:curl 10.10.0.44:1234 --connect-timeout 10 -m 20
来自:https://blog.csdn.net/weixin_30340745/article/details/98854529
执行一下命令安装以后就可以locate XXX了

yum install mlocate

sudo updatedb

locate  *.doc

实践如下:
在linux下搞软件开发的朋友, 几乎没有不知道strings命令的。我们先用man strings来看看:

strings - print the strings of printable characters in files.  

意思是, 打印文件中可打印的字符。  我来补充一下吧, 这个文件可以是文本文件(test.c), 可执行文件(test),  动态链接库(test.o), 静态链接库(test.a)


脱离代码地长篇大论而不去实际验证, 不是我的风格。 还是搞点代码下菜吧(代码存在test.c中):

cat test.c



我们来看看strings test.c的结果:
strings test.c


可以看到, 确实打印出了test.c中的很多字符。
下面, 我们对可执行文件用strings试试, 如下:
gcc test.c
strings a.out
/lib64/ld-linux-x86-64.so.2
__gmon_start__
libc.so.6
printf
__libc_start_main
GLIBC_2.2.5
fff.
fffff.
l$ L
t$(L
|$0H
oh, my dear, c isd

可以看到, 打印出了a.out中很多字符。
实际上, 如果有目标文件、静态库或动态库,, 也是可以用strings命令进行打印操作的。 我们来看看:
xxx.h文件:

xxx.c文件:
cat  xxx.c


然后, 我们来看看怎么制作静态、动态库吧(在后续博文中会继续详细介绍):
gcc -shared -fPIC -c xxx.c  #-fPI得加上,否则会报relocation R_X86_64_32 against `.rodata'
gcc -shared -fPIC -o libxxx.so xxx.o

问题:
gcc -shared -fPIC -o libxxx.so xxx.o
/usr/bin/ld: xxx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
解决办法:
gcc默认没加-fPIC参数,得手工加上即可。
strings xxx.o
rainy days

strings libxxx.a


strings libxxx.so

trings命令很简单, 看起来好像没什么, 但实际有很多用途。 下面, 我来举一个例子。  在大型的软件开发中, 假设有100个.c/.cpp文件, 这个.cpp文件最终生成10个.so库, 那么怎样才能快速知道某个.c/.cpp文件编译到那个.so库中去了呢? 当然, 你可能要说, 看makefile不就知道了。 对, 看makefile肯定可以, 但如下方法更好, 直接用命令:
      strings -f "*.so" | grep "xxxxxx"

      如果还不明白, 那就就以上面的小程序为例为说明, 不过, 此处我们考虑所有的文件, 如下:

strings -f * | grep "my dear"
a.out: oh, my dear, c isd
test.c:         printf("oh, my dear, c isd\n", c);

可以看到, 源文件test.c和可执行文件中皆有"my dear"串, 一下子就找到了对应的文件,清楚了吧。如果某.c/.cpp文件编译进了.so库, 那么,strings -f * | grep "my dear"必定可以找到对应的.so文件, 其中"my dear"为该.c/.cpp文件中的某个日志串(比如以printf为打印)。

来自:https://blog.csdn.net/stpeace/article/details/46641069
背景: 系统启动的grub.cfg 不一样,有的在/boot/efi/EFI/centos/grub.cfg ,有的在 /etc/grub2.cfg

某天挂载了一个新硬盘后,我的centos7系统第二天就出现了崩溃现象,报错如题“failed to start crash recovery kernel arming”.

意思大致为“内存崩溃捕获机制未能成功启动”,一搜才知道这是因为一个叫做kdump的服务无法启动导致的。

那么什么是kdump呢?

kdump 是一种先进的基于 kexec 的内核崩溃转储机制。当系统崩溃时,kdump 使用 kexec 启动到第二个内核。第二个内核通常叫做捕获内核,以很小内存启动以捕获转储镜像。第一个内核保留了内存的一部分给第二内核启动用。由于 kdump 利用 kexec 启动捕获内核,绕过了 BIOS,所以第一个内核的内存得以保留。这是内核崩溃转储的本质。详细的在:http://www.ibm.com/developerworks/cn/linux/l-cn-kdump1/index.html#major3

那接下来查找失败的原因:

看到一个博文中说与启动文件配置有关

查看/etc/grub.conf 文件,发现crashkernel=auto,

系统对crashkernel=auto的定义为:

如果系统的内存 <= 8 GB 对kdump kernel不会保留任何内容;也就是说,crashkernel=auto 等

于关掉了机器上的kdump功能;

如果系统的内存> 8 GB但是<= 16 GB,crashkernel=auto会保留256M,等同于crashkernel=256M;

如果系统内存> 16GB, crashkernel=auto会保留512M, 等同于crashkernel=512M

安装虚拟机时,给虚拟机设置的内存为1G,所以说系统关掉了kdump。

接下来就是改写配置,但是没能在系统中找到博文中所说的/etc/grub.conf这个文件,后来想到从Centos 7之后启动就采用grub2 了,所以vi /etc/grub2.cfg把其中的crashkernel=auto改成crashkernel=256M重启就成功了。

来自:https://www.jianshu.com/p/c9e741c24d2b
在mac下开发的时候,经常会发现有些文件的属性后面,有个@符号



如上图所示。为什么呢?


在mac os 下 HFS+的文件系统里,有时候有些文件会附加上mac的专有属性,@属性就表示文件或文件夹是来自互联网下载
去掉方法:
xattr -l 文件名:查看attr
xattr -d 属性名:删除attr


来自:https://blog.csdn.net/mysteryhaohao/article/details/51900188
mac下发现不能用记事本打开文本文件,ls -la 发现格式后面有个@:
https://blog.csdn.net/wk3368/article/details/29597535
如何用tar压缩文件夹到指定目录:
tar -zxvf /usr/local/jmeter.tar.gz -C /usr/local/  && rm -rf /usr/local/jmeter.tar.gz && chmod -R 755 /usr/local/jmeter

压缩:
tar -cvzf /test/tmp/abc.tar.gz /test/tcp/abc

实例,将魔方MYSIM数据库给压缩到根目录下:
tar -cvzf /mofang.08.21.tar.gz mofang/

解压
tar -cvxf abc.tar.gz  -C /test/tmp
导语
    Redhat企业级系统的6.7版自带SSH版本为OpenSSH_5.3p1, 基于审计和安全性需求,建议将其升级到最新的OpenSSH版本,当前官网最新版本为7.4p1. 本文档将详细介绍OpenSSH升级的完整步骤。需要说明的是,升级过程中虽然涉及zlib、openssl和openssh的卸载,但是并不会导致当前的ssh远程连接会话断开,因此是可以将整个升级过程写成自动化脚本以进行自动批量部署的。后面咱准备逐步过度到CentOS7了,新版在SSH底层上优化了TCP连接传输功能。在譬如拷贝时会用同一个TCP的FD,而旧版本的是没有这个功能的。再就是刚连接过了在超时设置范围内,再次发起连接时也会复用之前的一个Socket的FD句柄,提高连接效率。
编译安装OpenSSH7.4p1一共分二步,
第一步:安装编译需要的RPM包:


第二步:编译并安装到和原来一样的目录,如下步骤:
tar zxvf openssh-7.4p1.tar.gz
cd openssh-7.4p1
ll
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-kerberos5=/usr/lib64/libkrb5.so
make && make install
cp -rf /usr/local/src/openssh-7.4p1/contrib/redhat/sshd.init /etc/init.d/sshd  
cp -rf contrib/redhat/sshd.init /etc/init.d/sshd  
chmod +x /etc/init.d/sshd
chkconfig --add sshd
vim /etc/init.d/sshd
sed -i '/sbin/restorecon /etc/ssh/ssh_host_key.pub/s/^/#/'  /etc/init.d/sshd  
sed -i 's/#PermitRootLogin/PermitRootLogin/' /etc/ssh/sshd_config
vim /etc/ssh/sshd_config
ssh -V
service sshd restart
vim /etc/ssh/sshd_config
ll
vim /etc/ssh/sshd_config
ps -ef|grep ssh
service sshd start
history

附录:
反查一些OpenSSH需要的动态库,RPM包的安装路径辅助上面参数配置:
rpm -ql openssh-server-5.3p1-122.el6.x86_64
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/rc.d/init.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/libexec/openssh/sftp-server
/usr/libexec/openssh/ssh-keycat
/usr/sbin/.sshd.hmac
/usr/sbin/sshd
/usr/share/doc/openssh-server-5.3p1
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
/var/empty/sshd



ldd /usr/sbin/sshd
        linux-vdso.so.1 =>  (0x00007fffbc5ff000)
        libpam.so.0 => /lib64/libpam.so.0 (0x00007f2d19bf3000)
        libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f2d1980e000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f2d19605000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f2d19401000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007f2d191fe000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f2d18fe7000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f2d18db0000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f2d18b96000)
        libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f2d18951000)
        libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f2d1866a000)
        libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f2d1843e000)
        libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f2d18239000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2d17ea5000)
        libaudit.so.1 => /lib64/libaudit.so.1 (0x00007f2d17c89000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2d17a6b000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003c0e400000)
        libfreebl3.so => /lib64/libfreebl3.so (0x00007f2d177f4000)
        libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f2d175e9000)
        libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f2d173e5000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f2d171c6000)

rpm -qf /lib64/libpam.so.0 >> /tmp/jackRpmResult.txt
rpm -qf /usr/lib64/libcrypto.so.10 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/librt.so.1 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libdl.so.2 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libutil.so.1 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libz.so.1 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libcrypt.so.1 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libresolv.so.2 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libgssapi_krb5.so.2 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libkrb5.so.3 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libk5crypto.so.3 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libcom_err.so.2 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libc.so.6 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libaudit.so.1 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libpthread.so.0 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/ld-linux-x86-64.so.2 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libfreebl3.so >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libkrb5support.so.0 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libkeyutils.so.1 >> /tmp/jackRpmResult.txt
rpm -qf /lib64/libselinux.so.1 >> /tmp/jackRpmResult.txt

需要这些包:
rpm -qa|grep audit-libs-2.2-2
rpm -qa|grep glibc-2.12-1.192
rpm -qa|grep keyutils-libs-1.4-5
rpm -qa|grep krb5-libs-1.10.3-65
rpm -qa|grep libcom_err-1.41.12-23
rpm -qa|grep libselinux-2.0.94-7
rpm -qa|grep nss-softokn-freebl-3.14.3-9
rpm -qa|grep openssl-1.0.1e-57
rpm -qa|grep pam-1.1.1-24
rpm -qa|grep zlib-1.2.3-29


yum 安装软件包:
audit-libs-2.2-2 glibc-2.12-1.192 keyutils-libs-1.4-5 krb5-libs-1.10.3-65 libcom_err-1.41.12-23 libselinux-2.0.94-7 nss-softokn-freebl-3.14.3-9 openssl-1.0.1e-57 pam-1.1.1-24 zlib-1.2.3-29

去掉版本号直接安装:
yum install audit-libs glibc keyutils-libs krb5-libs libcom_err libselinux nss-softokn-freebl openssl pam zlib




参考编译来源:
(1)http://blog.chinaunix.net/uid-28266791-id-5759478.html
(2)https://www.cnblogs.com/xshrim/p/6472679.html
分页: 8/40 第一页 上页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 下页 最后页 [ 显示模式: 摘要 | 列表 ]