
Linux
文章平均质量分 63
taoyuanforrest
这个作者很懒,什么都没留下…
展开
-
GNU C 宏构造利器:语句表达式
GNU C 对 C 标准作了扩展,允许在一个表达式里内嵌语句,允许在表达式内部使用局部变量、for 循环和 goto 跳转语句。这样的表达式,我们称之为语句表达式。({ 表达式1;表达式2;表达式3;})语句表达式最外面使用小括号()括起来,里面一对大括号{}包起来的是代码块,代码块里允许内嵌各种语句。语句的格式可以是 “表达式;”这种一般格式的语句,也可以是循环、跳转等语句。跟一般表达式一样,语句表达式也有自己的值。语句表达式的值为内嵌语句中最后一个表达式的值。我们举个例子,使用语句表达式求值。转载 2024-06-14 16:08:05 · 176 阅读 · 0 评论 -
SO_REUSEPORT 之 TCP负载均衡验证
首先启动两个tcp server, 代码里开启 SO_REUSEPORT。从回复的server 进程id 可见,负载均衡做的很好。原创 2024-05-21 11:33:17 · 473 阅读 · 0 评论 -
linux本地随机端口范围及预留端口
linux随机端口原创 2023-03-13 15:45:04 · 939 阅读 · 0 评论 -
ICMP udp port unreachable
udp icmp原创 2023-03-13 15:37:35 · 1676 阅读 · 0 评论 -
TCP keepalive
tcp keepalive原创 2023-03-10 15:55:57 · 316 阅读 · 0 评论 -
glibc内存分配释放示例
glibc内存分配释放示例原创 2018-09-28 11:26:07 · 1802 阅读 · 0 评论 -
char*, char[], 字符串初始化之内存布局
先上一段C代码:#include <stdio.h>int a_test = 66;char glob_str_array[] = "Global Heglo String Array!";char *glob_str_pointer = "Global Hegxlo String Pointer!";main(){ a_test = 88; co...原创 2019-02-27 15:32:07 · 3965 阅读 · 0 评论 -
pthread相关函数
pthread_createhttp://man7.org/linux/man-pages/man3/pthread_create.3.htmlpthread_exithttp://man7.org/linux/man-pages/man3/pthread_exit.3.htmlpthread_joinhttp://man7.org/linux/man-pages/man3/p...原创 2019-01-07 10:47:42 · 1778 阅读 · 0 评论 -
chmod, fchmod修改文件权限
#include <sys/stat.h>int chmod(const char *path, mode_t mode);int fchmod(int fd, mode_t mode);示例:fp = fopen("/home/b001/file01", "w");/* change permissions to 644 */ if (fchmod...原创 2019-01-07 10:28:54 · 1601 阅读 · 0 评论 -
CAS原子操作以及Pthread Futex
维基百科给出的CAS定义:In computer science, compare-and-swap (CAS) is an atomic instruction used in multithreading to achieve synchronization. It compares the contents of a memory location with a given value ...原创 2019-01-11 11:52:27 · 1037 阅读 · 0 评论 -
SystemV与Posix IPC对比
原文:https://www.tutorialspoint.com/inter_process_communication/inter_process_communication_system_v_posix.htmImplement POSIX Semaphore APIs using System V Semaphores APIs:https://www.ibm.com/deve...转载 2019-01-11 11:45:59 · 915 阅读 · 0 评论 -
Pthread 线程调度
设置以下关于调度策略之前应该首先通过pthread_attr_setinheritsched设置PTHREAD_EXPLICIT_SCHED.1) Scheduling Scopehttp://man7.org/linux/man-pages/man3/pthread_attr_setscope.3.html通过pthread_attr_setscope()可以设置线程的资源竞争范围,包...原创 2019-01-11 11:37:31 · 2195 阅读 · 0 评论 -
linux调试工具集
除了GDB以外,linux还提供了很多的内存调试工具:注意:以下工具的使用之前,gcc需要使用-g编译出带符号的elf1) addr2line用于将可执行文件的虚拟内存地址或者动态库的偏移量转换成函数以及代码行。动态库的偏移量计算方式:将虚拟内存地址减去/proc/pid/maps中该动态库的虚拟内存起始地址示例: addr2line -C -f -e xxx.elf 0x123...原创 2018-07-27 17:09:55 · 8256 阅读 · 1 评论 -
linux下查看跟踪线程
假设进程为my_process:# ps -ef|grep my_processroot 10001 3322 0 14:05 ? 00:01:19 my_processroot 26844 23970 0 17:12 pts/0 00:00:00 grep my_process1) 通过ps命令查看线程,SPID是线程ID,STAT是线程状态...原创 2018-08-03 17:20:44 · 5161 阅读 · 0 评论 -
linux性能调试工具集
原文:http://www.brendangregg.com/linuxperf.html翻译 2018-08-03 14:23:01 · 773 阅读 · 0 评论 -
Linux readlink
例子:读取当前进程的绝对路径文件名int ret = readlink("/proc/self/exe", processBuf, sizeof(processBuf)-1);其中/proc/self/exe是指向当前进程的符号链接。[root@localhost self]$ pwd/proc/self[root@localhost self]$ ll exelrwxrwxr...原创 2018-08-08 10:50:24 · 1019 阅读 · 0 评论 -
gdb 常用命令
run/r 运行运行带参数的可执行文件:r 后面接参数,例如:$ gdb executablefile(gdb) r arg1 arg2 arg3continue/c 继续运行next/n 单步运行step/s 如果有函数则进入函数执行finish 跳出当前的函数jump/j 跳转到指定行/地址后继续执行,因此如果在跳转的目标行上如果没有设置断点,会继续往下执行...原创 2018-04-20 17:21:49 · 9553 阅读 · 1 评论 -
pipe/FIFO IPC
pipe与FIFO功能类似,都是单向通信。管道两端必须都open以后才可以通信,否则先open的一端默认阻塞。pipe作为无名管道,仅用于近亲进程,例如父子进程,同一个进程内的线程等等。FIFO作为有名管道,可用于两个独立进程的通信。介绍如下:http://man7.org/linux/man-pages/man7/pipe.7.htmlpipehttp://man7.or...原创 2019-01-03 17:17:08 · 472 阅读 · 0 评论 -
SystemV IPC 共享内存
shmgethttp://man7.org/linux/man-pages/man2/shmget.2.htmlshmathttp://man7.org/linux/man-pages/man2/shmat.2.htmlshmctlhttp://man7.org/linux/man-pages/man2/shmctl.2.htmlshmdthttp://man7.org/li...原创 2019-01-04 10:35:27 · 433 阅读 · 0 评论 -
SystemV IPC信号量
semgethttp://man7.org/linux/man-pages/man2/semget.2.htmlsemctlhttp://man7.org/linux/man-pages/man2/semctl.2.htmlsemophttp://man7.org/linux/man-pages/man2/semop.2.htmlftokhttp://man7.org/...原创 2019-01-10 13:19:12 · 334 阅读 · 0 评论 -
linux signal回调函数
void my_signal_handler(int sig){ printf("Received signal %d, quiting\n", sig); exit(1);}// set up signal handlersignal(SIGINT, my_signal_handler);signal(SIGQUIT, my_signal_handler);...原创 2019-01-10 17:13:27 · 1565 阅读 · 0 评论 -
多线程虚假唤醒 Spurious wakeup
问题描述:线程在等待signal信号时,即使等待的条件变量并没有变化,线程仍然可能被唤醒。解决的办法是设置一个while循环,检测条件变量是否真正改变了,如果没有就继续wait维基百科里的描述:Spurious wakeup describes a complication in the use of condition variables as provided by certain ...原创 2019-01-11 11:22:29 · 630 阅读 · 0 评论 -
进程分配内存的两种方式--brk() 和mmap()
内存分配转载 2018-06-06 11:03:04 · 1019 阅读 · 0 评论