System fork example
Simple example to fork child process and make it to do some work.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh sys_fork
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; sys_fork.ano
;
; To compile:
;
; $ ./build/ano ./examples/sys_fork/sys_fork.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME sys_fork
; @ANO_SCRIPT_VERSION 0.0.1
; @ANO_SCRIPT_DESCRIPTION Simple forking example
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; Example to fork child process and make it to do some work.
;
main [exit: 0] {
; Fork child process.
;
fork
mov _pid (rc)
; Parent process exits immediately…
;
cmp _pid (0)
jne "parent"
; …and child process does all the work.
;
mov _cmd ("uname")
exec (_cmd, "-o", "-p", "-m", "-r")
system ("hostname")
parent:
}
; ------------------------------------------------------------------------------ ; sys_fork.w2c ; ; To compile: ; ; $ ./build/widget ./examples/sys_fork/sys_fork.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; sys_fork.m2c ; ; To compile: ; ; $ ./build/menu ./examples/sys_fork/sys_fork.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.