linux进程相关系统文件 系统日志 共享内存管理
- 2015-11-02 22:46:00
- admin
- 原创 5672
一、linux进程相关系统文件
1、/proc/sys/kernel/pid_max:进程ID最大值,默认32768;
2、/proc/sys/kernel/threads-max:系统最大线程数,默认29732;
3、/proc/pid/fd:进程打开的所有fd,包括文件、设备、socket、pipe;
4、/proc/pid/task/tid:进程所有线程信息,主线程pid和tid一样;
5、/proc/pid/environ:进程所有环境变量;
/proc/net/tcp:
1、记录所有IPV4连接信息,netstat基于此文件实现;
2、文件内容都是16进制,80端口对应值是0050;
3、local_address本地地址,rem_address远程地址、st连接状态、inode文件描述符;
4、状态码:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/net/tcp_states.h
二、linux系统日志
查看系统日志:
1、cat /var/log/messages,查看系统日志,比如段错误、OOM;
2、journalctl --no-pager --since "2025-08-31 08:00:00" --until "2025-08-31 08:10:00",查看系统日志;
3、OOM Killer,Out Of Memory Killer,操作系统内存不足时,killer将会选择杀死某个进程;
4、oom_adj取值范围-17到15,-17这个进程就永远杀不掉;
5、oom_score_adj取值范围 -1000到1000,-1000这个进程就永远杀不掉,oom_adj底层使用oom_score_adj;
6、oom=oom_score+oom_score_adj,oom_score是根据内存消耗计算的分值,oom分值最高的进程被杀死;
杀死进程日志:
1、total-vm进程申请的虚拟内存,anon-rss进程使用的物理内存,file-rss映射到文件的内存;
2、Out of memory: Kill process 83437 (java) score 162 or sacrifice child
3、Killed process 83437 (java), UID 6001, total-vm:4804288kB, anon-rss:1301168kB, file-rss:0kB, shmem-rss:4kB
三、共享内存管理
系统共享内存配置:
1、shmmax,单块共享内存最大值;
2、shmmin,单块共享内存最小值;
3、shmseg,单个进程最多可以使用多少块共享内存;
4、shmmni,所有进程最多可以使用多少块共享内存;
5、shmall,系统总共可以分配多少共享内存,单位为页;
6、查看共享内存参数/proc/sys/kernel/varname;
ipcs - provide information on ipc facilities
1、-m shared memory segments
2、-q message queues
3、-s semaphore arrays
4、-a all (this is the default)
5、查询共享内存:ipcs -m
ipcrm [ -M key | -m id | -Q key | -q id | -S key | -s id ]
1、-m shmid:removes the shared memory segment identified by shmid after the last detach is performed.
2、-q msgid:removes the message queue identified by msgid.
3、-s semid:removes the semaphore identified by semid.
4、删除共享内存:ipcrm -m shmid