测试.S
.text
.global _start
_start:
xor %ax, %ax
mov %ax, %ds
mov %ax, %ss
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
Run Code Online (Sandbox Code Playgroud)
我通过这样做得到了反汇编代码文件
$ x86_64-elf-gcc -g -c -O0 -m32 -fno-pie -fno-stack-protector -fno-asynchronous-unwind-tables .\test.S
$ x86_64-elf-ld .\test.o -m elf_i386 -Ttext=0x7c00 -o test.elf
$ x86_64-elf-objdump -x -d -S -m i386 ./test.elf > test_dis.txt
Run Code Online (Sandbox Code Playgroud)
测试_dis.txt
./test.elf: file format elf32-i386
./test.elf
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00007c00
Program Header:
LOAD off 0x00000000 vaddr 0x00007000 paddr 0x00007000 align 2**12
filesz …Run Code Online (Sandbox Code Playgroud) 这是我的代码,忽略SIGCONT:
int main() {
signal(SIGCONT, SIG_IGN);
while(1);
}
Run Code Online (Sandbox Code Playgroud)
发生的情况是这样的:
> ./main &
[1] 25093
> kill -STOP 25093
[1]+ Stopped ./main
> ps -aux | grep 25093
xxx 25093 98.6 0.0 2488 872 pts/8 T 18:23 0:20 ./main
> kill -CONT 25093
> ps -aux | grep 25093
xxx 25093 52.1 0.0 2488 872 pts/8 R 18:23 0:28 ./main
Run Code Online (Sandbox Code Playgroud)
看来这SIGCONT仍然让我的过程继续下去。这是否意味着 的处理程序SIGCONT只是一个“副作用”?
我想知道什么时候SIGCONT该进程会再次运行?进程什么时候再次放入调度队列?是在kill执行系统调用时还是在调度进程时?(我读到一篇关于Linux信号的文章,指出调度代码没有SIGCONT特殊对待。代码段如下所示。)
> ./main &
[1] 25093
> …Run Code Online (Sandbox Code Playgroud) 这是我的代码
#include <pthread.h>
#include <stdio.h>
void cleanup(void *arg) {
printf("cleanup: %s\n", (const char*)arg);
}
void *thr_fn1(void *arg) {
printf("thread 1 strat\n");
pthread_cleanup_push(cleanup, (void*)"thread 1 first handler");
pthread_cleanup_push(cleanup, (void*)"thread 1 first handler");
if(arg)
return (void*)1;
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
return (void*)1;
}
void *thr_fn2(void *arg) {
printf("thread 2 strat\n");
pthread_cleanup_push(cleanup, (void*)"thread 2 first handler");
pthread_cleanup_push(cleanup, (void*)"thread 2 first handler");
if(arg)
return (void*)2;
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
return (void*)2;
}
int main() {
int err;
pthread_t tid1, tid2;
void *tret;
pthread_create(&tid1, NULL, thr_fn1, (void*)1);
pthread_create(&tid2, NULL, …Run Code Online (Sandbox Code Playgroud) 我认为atomic.Load(addr)应该等于*addr并且atomic.Store(addr, newval)应该等于*addr = newval。那么为什么这样做(使用*addror *addr = newval)不是原子操作呢?我的意思是它们最终会被解释为只是一条 cpu 指令(这是原子的)?