BASIC Developer & Support Resources > Scripting Languages

Fork

(1/1)

JRS:
I just stumbled upon the ScriptBasic UX extension module. It only has a couple Unix specific functions and one being a fork() call. It creates a duplicate process of the script your running. I was able to fork a Gtk example without any issues. I'm not sure how useful this is but I thought I would mention it.


--- Quote ---The fork() system call will spawn a new child process which is an identical process to the parent except that has a new system process ID. The process is copied in memory from the parent and a new process structure is assigned by the kernel. The return value of the function is which discriminates the two threads of execution. A zero is returned by the fork function in the child's process.

--- End quote ---


--- Code: ---INCLUDE ux.bas

pid = ux::fork()
pid = ux::fork()

IF pid THEN
  PRINT "MAIN:: Created a child process with a PID of ",pid,"\n"
ELSE
 PRINT "This is a child process with the PID of ",pid,"\n"
END IF

LINE INPUT x

--- End code ---

jrs@Laptop:~/SB/test$ scriba forkme.sb
MAIN:: Created a child process with a PID of 3353
This is a child process with the PID of 0
MAIN:: Created a child process with a PID of 3354
This is a child process with the PID of 0

Note: Satisfying the LINE INPUT of the main process and letting the program END will terminate the other child processes.

Navigation

[0] Message Index

Go to full version