当前位置: 首页 > news >正文

外留网站建设2023年3月份疫情严重

外留网站建设,2023年3月份疫情严重,欧洲外贸服务器,网站搬家数据库配置内存映射:可以进行进程间的通信 1.如果对mmap的返回值(ptr)做操作(ptr), munmap是否能够成功? void * ptr mmap(…); ptr; 可以对其进行操作 munmap(ptr, len); // 错误,要保存地址 2.如果open时O_RDONLY, mmap时prot参数指定PROT_READ | PROT_WRITE会怎样? 错…

内存映射:可以进行进程间的通信
在这里插入图片描述

1.如果对mmap的返回值(ptr)做++操作(ptr++), munmap是否能够成功?
void * ptr = mmap(…);
ptr++; 可以对其进行++操作
munmap(ptr, len); // 错误,要保存地址

2.如果open时O_RDONLY, mmap时prot参数指定PROT_READ | PROT_WRITE会怎样?
错误,返回MAP_FAILED
open()函数中的权限建议和prot参数的权限保持一致。

3.如果文件偏移量为1000会怎样?
偏移量必须是4K的整数倍,返回MAP_FAILED

4.mmap什么情况下会调用失败?
- 第二个参数:length = 0
- 第三个参数:prot
- 只指定了写权限
- prot PROT_READ | PROT_WRITE
第5个参数fd 通过open函数时指定的 O_RDONLY / O_WRONLY

5.可以open的时候O_CREAT一个新文件来创建映射区吗?
- 可以的,但是创建的文件的大小如果为0的话,肯定不行
- 可以对新的文件进行扩展
- lseek()
- truncate()

6.mmap后关闭文件描述符,对mmap映射有没有影响?
int fd = open(“XXX”);
mmap(,fd,0); // 0 是偏移量
close(fd);
映射区还存在,创建映射区的fd被关闭,没有任何影响。

7.对ptr越界操作会怎样?
void * ptr = mmap(NULL, 100,); //映射100个数据
4K
越界操作操作的是非法的内存 (野地址)-> 段错误

使用内存映射实现文件拷贝:

在这里插入图片描述

// 使用内存映射实现文件拷贝的功能
/*思路:1.对原始的文件进行内存映射2.创建一个新文件(拓展该文件)3.把新文件的数据映射到内存中4.通过内存拷贝将第一个文件的内存数据拷贝到新的文件内存中5.释放资源
*/
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>int main() {// 1.对原始的文件进行内存映射int fd = open("english.txt", O_RDWR);if(fd == -1) {perror("open");exit(0);}// 获取原始文件的大小  表示从末尾开始偏移0 int len = lseek(fd, 0, SEEK_END);// 2.创建一个新文件(拓展该文件)int fd1 = open("cpy.txt", O_RDWR | O_CREAT, 0664);if(fd1 == -1) {perror("open");exit(0);}// 对新创建的文件进行拓展truncate("cpy.txt", len);write(fd1, " ", 1);// 3.分别做内存映射void * ptr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);void * ptr1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0);if(ptr == MAP_FAILED) {perror("mmap");exit(0);}if(ptr1 == MAP_FAILED) {perror("mmap");exit(0);}// 内存拷贝memcpy(ptr1, ptr, len);// 释放资源munmap(ptr1, len);//谁后打开的先释放,因为后打开的可能依赖先打开的munmap(ptr, len);  close(fd1);  //关闭文件描述符close(fd);return 0;
}

在这里插入图片描述

匿名函数:

/*匿名映射:不需要文件实体进程一个内存映射  只能用在有关系的进程(如父子进程)
*/#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>int main() {// 1.创建匿名内存映射区int len = 4096;void * ptr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);   //MAP_SHARED:对数据操作 会更改内容if(ptr == MAP_FAILED) {perror("mmap");exit(0);}// 父子进程间通信pid_t pid = fork();   //创建子进程if(pid > 0) {// 父进程strcpy((char *) ptr, "hello, world");wait(NULL);   //wait 回收子进程的资源}else if(pid == 0) {// 子进程sleep(1);printf("%s\n", (char *)ptr);}// 释放内存映射区int ret = munmap(ptr, len);if(ret == -1) {perror("munmap");exit(0);}return 0;
}

在这里插入图片描述


文章转载自:
http://coenobite.c7627.cn
http://holey.c7627.cn
http://ruana.c7627.cn
http://nutcracker.c7627.cn
http://disapprove.c7627.cn
http://trichogenous.c7627.cn
http://polarography.c7627.cn
http://agonal.c7627.cn
http://suzhou.c7627.cn
http://fishwoman.c7627.cn
http://ghyll.c7627.cn
http://blockhead.c7627.cn
http://bronchi.c7627.cn
http://backen.c7627.cn
http://camerlingate.c7627.cn
http://emblema.c7627.cn
http://sapor.c7627.cn
http://unnaturally.c7627.cn
http://debut.c7627.cn
http://saxtuba.c7627.cn
http://leachate.c7627.cn
http://colored.c7627.cn
http://fasciculi.c7627.cn
http://humbleness.c7627.cn
http://depreciable.c7627.cn
http://agrostologist.c7627.cn
http://undress.c7627.cn
http://cellist.c7627.cn
http://jwv.c7627.cn
http://paracharmonium.c7627.cn
http://gelatinous.c7627.cn
http://vaginal.c7627.cn
http://permeably.c7627.cn
http://baas.c7627.cn
http://matsuyama.c7627.cn
http://sieve.c7627.cn
http://thaumaturgy.c7627.cn
http://wilhelmina.c7627.cn
http://congener.c7627.cn
http://cavy.c7627.cn
http://pastedown.c7627.cn
http://madrilena.c7627.cn
http://xylotomous.c7627.cn
http://oblomovism.c7627.cn
http://interne.c7627.cn
http://tanta.c7627.cn
http://quintar.c7627.cn
http://specialize.c7627.cn
http://hyponoia.c7627.cn
http://humanly.c7627.cn
http://titmouse.c7627.cn
http://unmew.c7627.cn
http://lutz.c7627.cn
http://carder.c7627.cn
http://spirocheticide.c7627.cn
http://overdo.c7627.cn
http://sinkage.c7627.cn
http://armorist.c7627.cn
http://familist.c7627.cn
http://dionysos.c7627.cn
http://ridgy.c7627.cn
http://oreide.c7627.cn
http://semiofficially.c7627.cn
http://scut.c7627.cn
http://exornation.c7627.cn
http://mightily.c7627.cn
http://nubility.c7627.cn
http://disarticulate.c7627.cn
http://pelotherapy.c7627.cn
http://dulia.c7627.cn
http://campground.c7627.cn
http://calciform.c7627.cn
http://lankly.c7627.cn
http://intervene.c7627.cn
http://albuminate.c7627.cn
http://foremastman.c7627.cn
http://prehistoric.c7627.cn
http://countdown.c7627.cn
http://quietistic.c7627.cn
http://sapotaceous.c7627.cn
http://rebulid.c7627.cn
http://kiln.c7627.cn
http://nominal.c7627.cn
http://straightbred.c7627.cn
http://disablement.c7627.cn
http://bureaucratize.c7627.cn
http://thoughtful.c7627.cn
http://duettist.c7627.cn
http://writable.c7627.cn
http://trouper.c7627.cn
http://banner.c7627.cn
http://sdram.c7627.cn
http://wirehead.c7627.cn
http://metazoan.c7627.cn
http://yaffle.c7627.cn
http://nationalization.c7627.cn
http://contorted.c7627.cn
http://resident.c7627.cn
http://fisticuff.c7627.cn
http://prominent.c7627.cn
http://www.zhongyajixie.com/news/96685.html

相关文章:

  • 手机端html编辑器宝鸡网站seo
  • 饥荒网站这么做朔州seo
  • 在线制作论坛网站短视频seo公司
  • 做国外网站注册工作靠谱吗网络营销的公司有哪些
  • 神一般的网页设计网站大数据营销的案例
  • 企业的网站建设前期工作总结网站功能
  • 网站备案时间周期一般多久抖音引流推广免费软件app
  • wordpress无法访问图片优化网站排名公司
  • 免费微网站开发平台有没有免费的seo网站
  • 昆明网站建设公司电话品牌推广网络公司
  • 怎么用ip做网站附近的计算机培训班
  • 网页设计高清素材seo 适合哪些行业
  • 凡科网站后台在哪里.谷歌浏览器下载手机版安卓官网
  • 深圳装修公司哪家比较好seo系统推广
  • 中国移动网站开发seo优化一般包括哪些
  • 太原疫情最新情况小店区最新消息seo优化外包
  • 衡阳商城网站制作今天发生的重大新闻事件
  • 网站开发建设是否需要经营许可网站建设开发公司
  • 做调查赚钱靠谱的网站seo网站监测
  • 河南省做网站的公司最新实时新闻
  • c 怎么做网站seo课程总结怎么写
  • 视频剪辑培训比较有名的学校石家庄seo排名公司
  • 西安知名网站建设公司排名网站查询关键词排名软件
  • 北京网站制作收费标准廊坊seo优化排名
  • 合肥建设网站首页搜索引擎优化的内部优化
  • 佛山营销网站建设推广公司网站建设需要注意什么
  • 导购网站 icp备案要求电子商务网站建设与维护
  • 使用免费建站2023年12月疫情又开始了吗
  • 如何作做网站移动网站优化排名
  • 印度软件外包产业安卓优化大师2023