自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(11)
  • 收藏
  • 关注

原创 Linux 进程 父进程等待子进程退出

wait()函数#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <sys/wait.h>#include <stdlib.h>int main(){ pid_t pid; int status; int data = 0; pid = fork(); if(pid == 0){ while(1){ printf("th

2021-11-11 12:08:52 253 1

原创 Linux进程(vfork函数创建子进程)

vfork函数也可以创建进程,与fork不同的是:1、vfork直接使用父进程存储空间,不拷贝2、vfork保证子进程先运行,当子进程调用exit退出后,父进程才开始执行。#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <unistd.h>int main(){ pid_t pid; int cnt; pid = vfork(); if(p

2021-11-02 21:21:21 519

原创 Linux进程(fork函数创建子进程)

1.使用fork函数创建一个子进程需要的头文件及函数原型如下:#include <sys/types.h>#include <unistd.h> pid_t fork(void);编写代码如下:#include <stdio.h>#include <sys/types.h>#include <unistd.h>int main(){ pid_t pid; pid = getpid(); for

2021-10-29 19:43:08 4539

原创 Linux文件编程:自己实现cp指令

自己实现cp指令简单来说需要以下几个步骤:1、打开源文件2、读取源文件的内容到缓冲区3、打开或者创建一个目标文件,这里需要注意的是,如果路径中已经存在目标文件,则需要清空目标文件里的内容。4、将缓冲区里存放的内容写入到目标文件。5.关闭源文件和目标文件#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include

2021-10-10 09:59:40 214

原创 Linux 文件编程 read函数

read函数的功能是向以打开的文件读取数据。read函数需要包含头文件 :#include <unistd.h>。read函数的原型为:ssize_t read(int fd, void *buf, size_t count);其中,fd为文件描述符;buf表示读出数据缓冲区地址;count表示读出的字节数。返回值:若读取成功,则返回读到的字节数;若失败,返回-1;若已达到文件尾,则返回0。因此读到的字节数可能小于count的值。#include <sys/t.

2021-10-08 14:00:05 16830

原创 Linux 文件编程 write函数

write 函数的功能是向已打开的文件写入数据write 函数还需要包含头文件#include <unistd.h>其函数原型为ssize_t write(int fd,void *buf,size_t count);其中,fd为文件描述符。buf表示写入文件的数据缓冲区地址。count 表示写入的字节数。#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h&g..

2021-10-07 15:32:51 837

原创 Linux 文件编程 open函数

open函数的功能是打开或创建文件,下面介绍函数所需的头文件、函数原型open函数所需头文件#include <sys/types.h>#include <sys/stat.h>#include <fcnl.h>open函数原型,其中参数pathname是要创建或者打开的文件的路径,flags用来标识打开方式int open(const char *pathname,int flags,mode_t mode);int open(const ch

2021-10-07 12:23:43 3105 1

原创 如何使用Ncurse?

#include<curses.h> //必须包含头文件int main(){ ininscr(); //Ncurse界面的初始化函数 printw("this is a test\n"); //在Ncurse模式下的printf getch(); //等待用户输入,如果没有这个语句,程序就直接退出了 endwin(); //程序退出,调用这个函数来恢复s.

2021-09-25 11:36:10 137

原创 基于Wemos的感应开盖垃圾桶

所需硬件weMos D1开发板;蜂鸣器;SG90舵机;代码如下#include<Servo.h> #define SERVO D5 //定义舵机信号口为D5脚#define Echo D2 //定义超声波模块响应信号口为D2脚#define Trig D8 //定义超声波模块触发信号口为D8脚#define BUZZER D3 //定义..

2021-09-07 22:07:27 134

原创 三个整数从小到大输出(代数法)

#include<stdio.h>int main(){ int tmp; int data1,data2,data3; printf("请输入三个整数:\n"); scanf("%d%d%d",&data1,&data2,&data3); if(data1>data2){ tmp = data1; data1 = data2; data2 = tmp; }if(da...

2021-09-03 13:11:21 252

原创 求最大公约数和最小公倍数

/***************************************** 求最大公约数:453%36=21; 36%21=15; 21%15=6; 15%6=3; 6%3=0; 最小公倍数:a * b / t (两数之积除以最大公约数)*****************************************/#include...

2021-08-18 18:21:44 240

空空如也

空空如也

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

TA关注的人

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