summary in July <test Nahanni shared memory>

Test shared memory

write shared memory on vm B 

xzl@xzl-test-second-vm:~/Xiaotest$ sudo ./write_shm abcdefg
The device address 0xe0000000 (lenth 268435456)
can be accessed over
logical address 0x7fddc081c000
*access_address = 1718121316
write a
write b
write c
write d
write e
write f
write g

read shared memory on vm A

xzl@xzl-test-first-vm:~/Xiaotest$ sudo ./read_shm 6
The device address 0xe0000000 (lenth 268435456)
can be accessed over
logical address 0x7f94ca9e3000
*access_address = 1684234849
read a
read b
read c
read d
read e
read f


write_shm.c

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>

#define UIO_DEV "/dev/uio0"  
#define UIO_ADDR "/sys/class/uio/uio0/maps/map1/addr"  
#define UIO_SIZE "/sys/class/uio/uio0/maps/map1/size"  

static char uio_addr_buf[16], uio_size_buf[16];

int main(int argc,  char ** argv)
{
  if(argc != 2){
        printf("<USAGE: cmmand value>\n");
        return 1;
  }
  int uio_fd, addr_fd, size_fd;
  int uio_size;
  int str_len = strlen(argv[1]);
  void* uio_addr, *access_address;
  int i,j;

  uio_fd = open(UIO_DEV, /*O_RDONLY*/O_RDWR);
  addr_fd = open(UIO_ADDR, O_RDONLY);
  size_fd = open(UIO_SIZE, O_RDONLY);
  if( addr_fd < 0 || size_fd < 0 || uio_fd < 0) {
       fprintf(stderr, "open: %s\n", strerror(errno));
       exit(-1);
  }
  read(addr_fd, uio_addr_buf, sizeof(uio_addr_buf));
  close(addr_fd);
  read(size_fd, uio_size_buf, sizeof(uio_size_buf));
  close(size_fd);
  uio_addr = (void*)strtoul(uio_addr_buf, NULL, 0);
  uio_size = (int)strtol(uio_size_buf, NULL, 0);

  access_address = mmap(NULL, uio_size, PROT_READ | PROT_WRITE,
                     MAP_SHARED, uio_fd, 1*getpagesize());
 if ( access_address == (void*) -1) {
      fprintf(stderr, "mmap: %s\n", strerror(errno));
      exit(-1);
  }
  printf("The device address %p (lenth %d)\n"
         "can be accessed over\n"
         "logical address %p\n", uio_addr, uio_size, access_address);

  printf("*access_address = %u\n",*((unsigned long*) access_address));
  for(i=0; i<str_len; i++) {
        (*((char *)(access_address + i))) = argv[1][i];
        printf("write %c\n",argv[1][i]);
  }
  munmap(access_address, uio_size);
  close(uio_fd);
  return 0;
}


read_shm.c

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>

#define UIO_DEV "/dev/uio0"  
#define UIO_ADDR "/sys/class/uio/uio0/maps/map1/addr"  
#define UIO_SIZE "/sys/class/uio/uio0/maps/map1/size"  

static char uio_addr_buf[16], uio_size_buf[16];

int main(int argc,  char ** argv)
{
  if(argc != 2){
        printf("<USAGE: cmmand count>\n");
        return 1;
  }
  int uio_fd, addr_fd, size_fd;
  int uio_size;
  int str_len = (int)strtol(argv[1],NULL,0);
  void* uio_addr, *access_address;
  int i,j;

  uio_fd = open(UIO_DEV, /*O_RDONLY*/O_RDWR);
  addr_fd = open(UIO_ADDR, O_RDONLY);
  size_fd = open(UIO_SIZE, O_RDONLY);
  if( addr_fd < 0 || size_fd < 0 || uio_fd < 0) {
       fprintf(stderr, "open: %s\n", strerror(errno));
       exit(-1);
  }
  read(addr_fd, uio_addr_buf, sizeof(uio_addr_buf));
  close(addr_fd);
  read(size_fd, uio_size_buf, sizeof(uio_size_buf));
  close(size_fd);
  uio_addr = (void*)strtoul(uio_addr_buf, NULL, 0);
  uio_size = (int)strtol(uio_size_buf, NULL, 0);

  access_address = mmap(NULL, uio_size, PROT_READ | PROT_WRITE,
                     MAP_SHARED, uio_fd, 1*getpagesize());
if ( access_address == (void*) -1) {
      fprintf(stderr, "mmap: %s\n", strerror(errno));
      exit(-1);
  }
  printf("The device address %p (lenth %d)\n"
         "can be accessed over\n"
         "logical address %p\n", uio_addr, uio_size, access_address);

  printf("*access_address = %u\n",*((unsigned long*) access_address));

  for(i=0; i<str_len; i++) {
        printf("read %c\n",*((char *)(access_address+i)));
  }
  munmap(access_address, uio_size);
  close(uio_fd);
  return 0;
}




使用python bs4库从下面这段内容“<div class="maingrid" data-v-0f3d927f=""> <!-- --> <!-- --> <!-- --> <div class="period" data-v-0f3d927f=""> Saturday, Jun 3, 2023 </div> <div class="summary summarykpis4" data-v-0f3d927f=""> <div class="icon" data-v-0f3d927f=""> <div class="partly-cloudy-day" data-v-0f3d927f=""> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Max </div> <div> 28℃ </div> <div class="normals"> <div> 22 </div> <div> 27 </div> <div> 36 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Min </div> <div> 13℃ </div> <div class="normals"> <div> 9.9 </div> <div> 15 </div> <div> 19 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Rain </div> <div> 0mm </div> <div class="normals"> <div> 0 </div> <div> 4.3 </div> <div> 23 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Precip % </div> <div> 0% </div> <!-- --> </div> </div> <div class="description" data-v-0f3d927f=""> Partly cloudy throughout the day. </div> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> </div>”提取出6月3至6月5日天气信息
06-04
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值