I’m running NASM x86_64 bit assembly on WSL. I’d have expected syscall_vfork to execute processes in parallel, yet it simply runs the child, then the parent.
bits 64
default rel
%include "stringfns.asm" ; basic print functionality
section .data
count: dw 0
section .text
global main
main:
mov r15, 0
spawner:
mov rax, 58
syscall
cmp rax, 0
je child
call debug ; prints 0n, occurs after child has finished
inc r15
cmp r15, 16
jne spawner
jmp exit
child:
mov r15, 0
.loop:
inc r15
cmp r15, 1000 ; execute child for some amount of time
jne .loop
inc word [count]
xor rsi, rsi
mov si, [count]
call iprintln ; prints integer in rsi
exit:
mov rax, 60
mov rdi, 0
syscall
I’ve also set max parallel threads to sixteen, without effect
user26752091 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
See the man page – the description of the vfork()
system call is “create a child process and block parent“. So what you’re seeing is the intended, documented behavior.
Once upon a time, vfork()
would run the parent and child concurrently while sharing an address space, but this caused a lot of problems, so Linux changed it so as to block the parent. If you read something that told you differently, it’s obsolete and you might not want to use that resource anymore.
If you want to copy the address space instead of sharing it, use fork()
. If you want to share the address space and run concurrently, so that you’re creating threads instead of processes, you need to use clone()
, or better, the higher-level and more-portable pthread_*
functions.