Linux下开发的一些总结
-
软链接的建立:ln -s a b 中的 a 就是源文件,b是链接文件名,
软连接的删除:rm -rf b 注意不是rm -rf b/
简单来说就是:使用 lsof|grep delete 来查看有哪些文件出了问题,第二列是进程号,如下所示:
[root@localhost Severice-GC]# lsof|grep delete
tuned 1357 root 8u REG 253,0 4096 70020876 /tmp/ffipTeUTs (deleted)
gmain 1357 2174 root 8u REG 253,0 4096 70020876 /tmp/ffipTeUTs (deleted)
tuned 1357 2177 root 8u REG 253,0 4096 70020876 /tmp/ffipTeUTs (deleted)
tuned 1357 2201 root 8u REG 253,0 4096 70020876 /tmp/ffipTeUTs (deleted)
tuned 1357 2212 root 8u REG 253,0 4096 70020876 /tmp/ffipTeUTs (deleted)
mysqld 19954 mysql 4u REG 253,0 0 67160552 /tmp/#67160552 (deleted)
mysqld 19954 mysql 5u REG 253,0 0 67160553 /tmp/#67160553 (deleted)
mysqld 19954 mysql 6u REG 253,0 0 67160554 /tmp/#67160554 (deleted)
mysqld 19954 mysql 13u REG 253,0 0 67160555 /tmp/#67160555 (deleted)
mysqld 19954 5072 mysql 4u REG 253,0 0 67160552 /tmp/#67160552 (deleted)
mysqld 19954 5072 mysql 5u REG 253,0 0 67160553 /tmp/#67160553 (deleted)
mysqld 19954 5072 mysql 6u REG 253,0 0 67160554 /tmp/#67160554 (deleted)
然后使用 kill -9 + 进程号删除进程,比如 kill -9 19954,进程号时lsof|grep delete查询结果的第二列。
- 添加 动态库/静态库 的查找路径,LINUX动态库(.SO)搜索路径(目录)设置方法
1.vim /etc/ld.so.conf
添加路径后执行 ldconfig 指令;
2.使用 export LD_LIBRARY_PATH=”LD_LIBRARY_PATH:/opt/” 添加路径 /opt/。
- 在ld.so.conf加入/usr/local/lib,会导致yum出问题
ImportError: /usr/lib64/python2.7/site-packages/pycurl.so: undefined symbol: CRYPTO_num_locks
您在 /var/spool/mail/root 中有新邮件
整体显示如下:
[root@localhost Severice-GC]# debuginfo-install expat-2.1.0-12.el7.x86_64 libuuid-2.23.2-65.el7_9.1.x86_64 mariadb-libs-5.5.68-1.el7.x86_64 nss-softokn-freebl-3.53.1-6.el7_9.x86_64
Traceback (most recent call last):
File "/usr/bin/debuginfo-install", line 21, in <module>
import yum
File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 59, in <module>
import config
File "/usr/lib/python2.7/site-packages/yum/config.py", line 30, in <module>
from parser import ConfigPreProcessor, varReplace
File "/usr/lib/python2.7/site-packages/yum/parser.py", line 4, in <module>
import urlgrabber
File "/usr/lib/python2.7/site-packages/urlgrabber/__init__.py", line 55, in <module>
from grabber import urlgrab, urlopen, urlread
File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 550, in <module>
import pycurl
ImportError: /usr/lib64/python2.7/site-packages/pycurl.so: undefined symbol: CRYPTO_num_locks
您在 /var/spool/mail/root 中有新邮件
- CMAKE的宏,CMAKE_CONFIGURATION_TYPES和CMAKE_BUILD_TYPE有以下几个选项:Release、Debug、RelWithDebInfo。官方说明为:
Specifies the available build types on multi-config generators.
This specifies what build types (configurations) will be available such as Debug, Release, RelWithDebInfo etc.
This has reasonable defaults on most platforms, but can be extended to provide other build types.
- 端口占用导致登录问题
[root@localhost build]# netstat -anp |grep 8081
tcp 29 0 0.0.0.0:8081 0.0.0.0:* LISTEN 27915/GC_SEVER
tcp 218 0 10.8.9.190:8081 10.8.9.69:64251 CLOSE_WAIT -
解决方式,查到对应的PID,将其结束掉。
流程如下:
在本例中,假设8080端口被占用。
1.查看8080端口是否被占用
1
2
netstat -anp | grep 8080
输出结果:tcp 0 0 :::8080 :::* LISTEN 3000/java
由上可知8080端口已经被开启。
2.查看占用8080端口的进程:
fuser -v -n tcp 8080
输出结果:
USER PID ACCESS COMMAND 8080/tcp:
zhu 1154 F.... java
3.杀死占用8080端口的进程:
kill -s 9 1154(自己的进程号).
4.查看所有进程:
ps
输出结果:
PID TTY TIME CMD
2949 pts/1 00:00:00 bash
3037 pts/1 00:00:00 ps
这是便可发现1154进程已经不存在了
详见:https://www.jb51.net/article/167072.htm
- (8条消息) linux tcpdump 抓包_vinson的博客-CSDN博客—注意:命名要结合正确的网卡名一起使用,使用ifconfig来查看网卡名称;
抓包并写入文件中:tcpdump -i ens192 -c 10000 -w one.cap 此条命令的意思是,监听ens33网卡,抓5000个包停止,并将文件写入one.cap文件中,cap文件使用wireshark打开。
Linux tcpdump命令详解 - ggjucheng - 博客园 (cnblogs.com)
- 网络上的其他方式都没法使用的情况下,使用如下方式将void * 转 int
(8条消息) 关于void与int的强制转换_SimpleCode-CSDN博客_void转int
int cast(void *arg)
{
int tmp;
memcpy(&tmp, (void *)&arg, 4); //这是最让我觉得它怪异的地方,本来把指针当作整型变量用了,要恢复就只能取地址,再加上参数是void*,这真是够整洁的。
return tmp;
-
Linux下cgdb的使用
中文教程(部分):cgdb中文教程 —这个系列的其他博客也可以看一看。
英语教程: 英文教程 -
gdb打印技巧
https://www.jianshu.com/p/98c923a671ae
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
int main()
{
struct ifreq ifr;
struct ifconf ifc;
char buf[2048];
int success = 0;
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1)
{
printf("socket error\n");
return -1;
}
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1)
{
printf("ioctl error\n");
return -1;
}
struct ifreq *it = ifc.ifc_req;
const struct ifreq *const end = it + (ifc.ifc_len / sizeof(struct ifreq));
char szMac[64];
int count = 0;
for (; it != end; ++it)
{
strcpy(ifr.ifr_name, it->ifr_name);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0)
{
if (!(ifr.ifr_flags & IFF_LOOPBACK))
{ // don't count loopback
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0)
{
count++;
unsigned char *ptr;
ptr = (unsigned char *)&ifr.ifr_ifru.ifru_hwaddr.sa_data[0];
snprintf(szMac, 64, "%02X:%02X:%02X:%02X:%02X:%02X", *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3), *(ptr + 4), *(ptr + 5));
printf("%d,Interface name : %s , Mac address : %s \n", count, ifr.ifr_name, szMac);
}
}
}
else
{
printf("get mac info error\n");
return -1;
}
}
}
在Linux下获取mac地址和网卡名称;
详见:https://blog.csdn.net/vertor11/article/details/78466160
- linux下查看端口占用情况
常用命令格式#netstat -anutp
参数含义:
-a 显示所有
-n 以ip形式显示当前建立的有效连接和端口
-u 显示UDP协议
-t 显示TCP协议
-p 显示对应PID与程序名
详见:https://www.php.cn/linux-461159.html
netstat -tunlp | grep 8000 //查看 8000 端口的情况
netstat -ntlp //查看当前所有tcp端口
netstat -ntulp | grep 80 //查看所有80端口使用情况
netstat -ntulp | grep 3306 //查看所有3306端口使用情况
lsof -i:8000 //查看 8000 端口的情况
lsof -i
netstat -s -u:查看接受的包存在什么问题
netstat指令介绍:
https://blog.csdn.net/dongl890426/article/details/86981901(详细)
https://blog.csdn.net/luoyir1997/article/details/80551297
- netstat -su
在linux下查看网卡接受的包的一些信息;
例如:
[root@localhost linux]# netstat -su
IcmpMsg:
InType3: 2423
InType8: 16739
OutType0: 16739
OutType3: 185850
Udp:
1326107 packets received
275426 packets to unknown port received.
425419 packet receive errors
195526 packets sent
425419 receive buffer errors
0 send buffer errors
UdpLite:
IpExt:
InNoRoutes: 2
InMcastPkts: 1026972
OutMcastPkts: 31
InBcastPkts: 1818635
InOctets: 2438311618
OutOctets: 1887407170
InMcastOctets: 174732269
OutMcastOctets: 4698
InBcastOctets: 342817536
InNoECTPkts: 9492091
- linux下查看进程并杀死进程
ps - ef | grep 程序名称
或者使用 ps -af,这样列出的进程会少很多;
使用 ** killall 进程名 ** 的方式杀死进程;也可以使用 kill -9 进程PID 的方式来达到同样目的;
- Linux下查看网卡 信息使用 ifconfig,Windows下使用systeminfo;
- GDB调试时,打印结构体时,使用语句
set print pretty on
,可以将结构体显示得更加好看;(使用p 结构体变量名
即可打印出结构体信息)
echo "Hello World\!" | nc -4u 10.8.9.190 8888
tcpdump -i ens192 -nn -vv -X udp port 8888
第一行是向10.8.9.190的8888端口发送一个信息–hello world!。
第二行是在10.8.9.190下监听ens192网卡,得到8888端口收到的信息;
- tcpdump -i eth0 icmp:监听网卡eth0上的所有icmp协议
tcpdump -i eth0 http:监听网卡eth0上的所有http协议
- libcurl使用方法介绍: https://www.cnblogs.com/heluan/p/10177475.html
官网说明:https://curl.se/libcurl/c/curl_multi_perform.html
- linux下丢包分析思路:Linux 系统 UDP 丢包问题分析思路
开启tcpdump抓包,并将结果转存为文件
tcpdump tcp -s 0 port 80 -w ./http.cap
抓取所有包使用使用:
tcpdump -w output.cap