自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

linuxcpp_的博客

苟有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。

  • 博客(21)
  • 收藏
  • 关注

原创 信号

信号信号的概念信号的机制与信号相关的事件和状态产生信号递达未决信号的处理方法阻塞信号集(信号屏蔽字)未决信号集信号的编号信号 4 要素信号的概念信号在我们的生活中随处可见, 如:古代战争中摔杯为号;现代战争中的信号弹;体育比赛中使用的信号枪…他们都有共性: 1. 简单 2. 不能携带大量信息 3. 满足某个特设条件才发送。信号是信息的载体, Linux/UNIX 环境下,古老、经典的通信方式, 现下依然是主要的通信手段。Unix 早期版本就提供了信号机制,但不可靠,信号可能丢失。Berkeley

2020-12-27 03:49:56 886 1

原创 Linux进程间通信

Linux进程间通信IPC方法管道管道的概念IPC方法Linux 环境下,进程地址空间相互独立,每个进程各自有不同的用户地址空间。任何一个进程的全局变量在另一个进程中都看不到,所以进程和进程之间不能相互访问,要交换数据必须通过内核,在内核中开辟一块缓冲区,进程 1 把数据从用户空间拷到内核缓冲区,进程 2 再从内核缓冲区把数据读走,内核提供的这种机制称为进程间通信(IPC, InterProcess Communication)。在进程间完成数据传递需要借助操作系统提供特殊的方法,如:文件、管道、信

2020-12-08 14:39:24 180

原创 Linux进程概述

进程进程相关概念程序和进程并发单道程序设计多道程序设计CPU 和 MMU (虚拟内存映射单元)进程控制块 PCB进程状态环境变量常见环境变量PATHSHELLTERMLANGHOMEgetenv 函数setenv 函数unsetenv 函数进程控制fork 函数getpid 函数getppid 函数getuid 函数getgid 函数进程共享exec 函数族execlp 函数execl 函数execvp 函数exec 函数族一般规律回收子进程孤儿进程僵尸进程wait 函数进程相关概念程序和进程​ 程

2020-12-01 14:19:53 733

原创 初识C++以及C++对C的加强

初识C++以及C++对C的增强和扩展1 C++ 概述1.1 C++两大编程思想1.2 C++移植性和标准2 初识C++2.1 面向对象的三大特性2.2 头文件以及标准命名空间2.3 双冒作用域运算符2.4 namespace命名空间1 C++ 概述1.1 C++两大编程思想1. 面向对象2. 泛型编程1.2 C++移植性和标准ANSI在1998制定出C++第一套标准(C++98)2 初识C++2.1 面向对象的三大特性封装、继承、多态2.2 头文件以及标准命名空间#include

2020-12-31 02:00:37 602

原创 catch_child.cpp

/* * function: 父进程使用sigaction()函数捕捉SIGCHLD信号子进程 * * 2020-12-27 */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <sys/wait.h>void func(int signo){ pid_t wpid; int status

2020-12-27 03:45:53 282

原创 sigaction.cpp

/* * function: 使用sigaction函数注册一个信号的捕捉函数 * * 2020-12-26 */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <signal.h>// 信号的捕捉函数void func(int signum){ printf("hello world\n"); return;}int main(

2020-12-26 16:00:46 102

原创 signalset.cpp

/* * function: 将2号信号(Ctrl+c)和20号信号(ctrl+z)屏蔽 * * 2020-12-26 */#include <stdio.h>#include <unistd.h>#include <signal.h>#include <stdlib.h>void print(sigset_t *set){ int ret = sigpending(set); // 读取当前进程的未决信号集 if (r

2020-12-26 15:11:20 85

原创 setitimer.cpp

/* * function: 使用setitimer函数实现定时以及周期定时 * * 2020-12-23 */#include <stdio.h>#include <unistd.h>#include <signal.h>#include <sys/time.h>void print(int sig){ // 注意:如果结尾不加\n,打印不出来,暂不知道原因 printf("catch signal %d,hello

2020-12-23 13:25:20 113

原创 alarm.cpp

/* * function: 使用alarm函数,计算计算机1秒可以数多少个数。 * * 2020.12.20 */#include <stdio.h>#include <unistd.h>#include <fcntl.h>int main(int argc, char *argv[]){ int ii = 0; int fd = open("alarm.txt", O_WRONLY | O_CREAT | O_TRUNC, 064

2020-12-20 00:39:45 134 1

原创 共享内存用于进程间通信

共享内存用于进程间通信共享内存在父子进程间通信示例共享内存在无血缘关系进程间通信写端示例读端示例共享内存在父子进程间通信示例/* * function: 演示使用mmap()函数实现使用共享映射区完成父子进程间通信 * * 2020-12-07 */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <fcntl.

2020-12-08 14:12:01 110 1

原创 UNIX域套接字

UNIX域套接字[udp]服务端客户端服务端/* * function: 演示本地unix域套接字用于进程间通信 * 此进程为服务端 * * 2020-12-05 */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/socket.h>#include <sys/un.h> // struct sockad

2020-12-07 20:16:28 146

原创 mkfifo_w/mkfifo_r.cpp

mkfifo_w.cpp/* * function: 演示使用mkfifo创建管道,并实现无血缘关系的进程间通信 * 此进程为写端 * * 2020-12-05 */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/stat.h>#include <fcntl.h>int main(int argc, char

2020-12-05 20:16:15 84

原创 pipe 实现命令 ls | wc -l

/* * function: 使用管道实现父子进程间通信,完成: ls | wc –l。 * * 2020-12-01 */#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main(int argc, char *argv[]){ int fd[2] = {0}; int ret = pipe(fd); // 创建管道 if (ret < 0)

2020-12-01 22:15:02 581

原创 pipe.cpp

/* * function: 演示使用pipe函数创建管道,并完成进程间通信 * * int pipe(int fildes[2]); // 成功:0,失败:-1,设置errno * * 2020-12-01 */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, char *argv[]){

2020-12-01 21:35:38 125

原创 exec_ps.cpp

/* * function: 使用exec函数族中的函数,执行ps -ef命令,并将结果输出到文件中。 */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <fcntl.h>int main(int argc, char *argv[]){ int fd = open("./a.txt", O_RDWR | O_CREAT, 0644); // 打开a

2020-12-01 14:38:54 159

原创 exec_ls.cpp

/* * function: 练习使用exec函数族中的函数 */#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main(int argc, char *argv[]){ //execlp("ls", "-l", "-h", NULL); // 错误写法 // 正确写法: execlp("ls", "ls", "-l", "-h", NULL);

2020-12-01 14:35:01 140

原创 fork.cpp

/* * function: fork一个子进程,并打印其相应pid * * 2020-12-01 */#include <stdio.h>#include <unistd.h>#include <stdlib.h>int main(int argc, char *argv[]){ printf("===before fork-1===\n"); printf("===before fork-2===\n"); printf

2020-12-01 14:30:15 135

原创 getenv.cpp

/* * function: 打印环境变量(修改或删除环境变量) * * 2020-12-01 */#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]){ char *buf = NULL; buf = getenv("HOME"); printf("HOME = %s\n", buf); buf = getenv("SHELL");

2020-12-01 14:27:30 100

原创 wait回收同时关系子进程回收状态

/* * function: 演示wait函数阻塞回收子进程 * * pid_t wait(int *status); // 成功:清理掉的子进程 ID;失败: -1 (没有子进程) * * 三组宏函数: * 1. WIFEXITED(status) 为非 0 → 进程正常结束 * WEXITSTATUS(status) 如上宏为真,使用此宏 → 获取进程退出状态 (exit 的参数) * * 2. WIFSIGNALED(status) 为非 0 → 进程异常终止 * WT

2020-12-01 14:02:01 103

原创 wait回收并不关心子进程退出状态

/* * function: 演示wait函数阻塞回收子进程 * * pid_t wait(int *status); // 成功:清理掉的子进程 ID;失败: -1 (没有子进程) * * 三组宏函数: * 1. WIFEXITED(status) 为非 0 → 进程正常结束 * WEXITSTATUS(status) 如上宏为真,使用此宏 → 获取进程退出状态 (exit 的参数) * * 2. WIFSIGNALED(status) 为非 0 → 进程异常终止 * WT

2020-12-01 11:18:45 190

原创 标准库string类基本用法

string类1 基本介绍与头文件2 string对象的定义和初始化2.1 拷贝初始化2.2 直接初始化3 string对象上的操作4 string操作实例4.1 读写string对象4.2 读取未知数量的string对象4.3 使用getline读取一整行4.4 string的empty()和size()操作4.5 比较string对象4.6 为string对象赋值4.7 两个string对象相加4.8 字面值和string对象相加5 处理string对象中的字符5.1 处理每个字符5.2 处理部分字符

2020-12-01 00:37:28 694 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除