You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
1.9 KiB
Python
97 lines
1.9 KiB
Python
import time
|
|
import mmap
|
|
import os
|
|
import threading
|
|
import ctypes
|
|
|
|
cnt = 0
|
|
print(cnt, "hello", time.time())
|
|
|
|
while True:
|
|
cnt += 1
|
|
# if cnt % 1000_0000 == 0:
|
|
# print(cnt, "hello", time.time())
|
|
|
|
# print(cnt, "hello", time.time())
|
|
# time.sleep(0.01)
|
|
|
|
|
|
|
|
def read_memory(address):
|
|
# 创建一个足够大的缓冲区来读取内存
|
|
buffer_size = 8 # 假设我们读取的是一个64位整数
|
|
buffer = ctypes.create_string_buffer(buffer_size)
|
|
|
|
# 使用ctypes的cast函数将地址转换为ctypes的指针类型
|
|
ptr = ctypes.cast(address, ctypes.POINTER(ctypes.c_char * buffer_size))
|
|
|
|
# 读取内存到buffer中
|
|
ptr.contents[:buffer_size]
|
|
|
|
# 解析buffer中的数据
|
|
data = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_int8)).contents.value
|
|
return data
|
|
|
|
|
|
|
|
print(os.getpid())
|
|
print(os.getpgid(os.getpid()))
|
|
|
|
|
|
def t():
|
|
time.sleep(100)
|
|
cnt = 0
|
|
while True:
|
|
cnt += 1
|
|
|
|
|
|
t = threading.Thread(target=t)
|
|
t.start()
|
|
|
|
|
|
def dealy():
|
|
time.sleep(100000)
|
|
# time.sleep(20)
|
|
print("start")
|
|
|
|
with open("/tmp/test/data", "r+b") as f:
|
|
mm = mmap.mmap(f.fileno(), 0, mmap.PROT_READ | mmap.MAP_PRIVATE)
|
|
for i in range(400):
|
|
for _ in range(1024 * 1024):
|
|
idx = _ * i
|
|
a = mm[idx]
|
|
mm[idx] = idx % 230
|
|
|
|
# memory_block = bytearray(1024*1024)
|
|
# lis.append(memory_block)
|
|
|
|
time.sleep(1)
|
|
print(i, idx, mm[idx], a)
|
|
print("ok")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# import time
|
|
# from datetime import datetime
|
|
# import urllib.request
|
|
|
|
# while True:
|
|
# time.sleep(1)
|
|
# now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
# print(now)
|
|
# try:
|
|
# request = urllib.request.Request("http://www.baidu.com")
|
|
# with urllib.request.urlopen(request) as response:
|
|
# data = response.read()
|
|
# content = data.decode("utf-8")
|
|
# print(f"{len(content)}")
|
|
# except Exception as e:
|
|
# print(e)
|
|
|
|
|