langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,6 @@
#load "unix.cma";;
let pid = Unix.fork ();;
if pid > 0 then
print_endline "This is the original process"
else
print_endline "This is the new process";;

30
Task/Fork/Oz/fork.oz Normal file
View file

@ -0,0 +1,30 @@
declare
ParentVar1 = "parent data"
ParentVar2
functor RemoteCode
export
result:Result
import QTk at 'x-oz://system/wp/QTk.ozf'
define
Result
%% Show a simple window. When it is closed by the user, set Result.
Window =
{QTk.build
td(action:proc {$} Result = 42 end %% on close
label(text:"In child process: "#ParentVar1))} %% read parent process variable
{Window show}
!ParentVar2 = childData %% write to parent process variable
{Wait Result}
end
%% create a new process on the same machine
RM = {New Remote.manager init(host:localhost)}
%% execute the code encapsulated in the given functor
RemoteModule = {RM apply(RemoteCode $)}
in
%% retrieve data from child process
{Show RemoteModule.result} %% prints 42
%% exit child process
{RM close}
{Show ParentVar2} %% print "childData"

View file

@ -0,0 +1,8 @@
void
foo()
{
if (pari_daemon())
pari_printf("Original\n");
else
pari_printf("Fork\n");
}

1
Task/Fork/PL-I/fork.pli Normal file
View file

@ -0,0 +1 @@
ATTACH SOLVE (X) THREAD (T5);

View file

@ -0,0 +1,9 @@
use NativeCall;
sub fork() returns Int is native { ... }
if fork() -> $pid {
print "I am the proud parent of $pid.\n";
}
else {
print "I am a child. Have you seen my mommy?\n";
}

View file

@ -0,0 +1,7 @@
lvars ress;
if sys_fork(false) ->> ress then
;;; parent
printf(ress, 'Child pid = %p\n');
else
printf('In child\n');
endif;

View file

@ -0,0 +1,7 @@
run "someProgram.bas",#handle
render #handle ' this runs the program until it waits
' both the parent and child are running
' --------------------------------------------------------
' You can also call a function in the someProgram.bas program.
' For example if it had a DisplayBanner Funciton.
#handle DisplayBanner("Welcome!")

View file

@ -0,0 +1,6 @@
p@(Process traits) forkAndDo: b
[| ret |
(ret := lobby cloneSystem)
first ifTrue: [p pipes addLast: ret second. ret second]
ifFalse: [[p pipes clear. p pipes addLast: ret second. b applyWith: ret second] ensure: [lobby quit]]
].

View file

@ -0,0 +1,3 @@
case Posix.Process.fork () of
SOME pid => print "This is the original process\n"
| NONE => print "This is the new process\n";

3
Task/Fork/Toka/fork.toka Normal file
View file

@ -0,0 +1,3 @@
needs shell
getpid is-data PID
[ fork getpid PID = [ ." Child PID: " . cr ] [ ." In child\n" ] ifTrueFalse ] invoke

View file

@ -0,0 +1,11 @@
i=0
(while test $i -lt 10; do
sleep 1
echo "Child process"
i=`expr $i + 1`
done) &
while test $i -lt 5; do
sleep 2
echo "Parent process"
i=`expr $i + 1`
done

View file

@ -0,0 +1,5 @@
(for ((i=0;i<10;i++)); do sleep 1; echo "Child process"; done) &
for ((i=0;i<5;i++)); do
sleep 2
echo "Parent process"
done

View file

@ -0,0 +1 @@
(echo "Process 1" >&2 ;sleep 5; echo "1 done" ) | (echo "Process 2";cat;echo "2 done")

View file

@ -0,0 +1,32 @@
extern fork
extern printf
section .text
global _start
_start:
call fork
cmp eax, 0
je _child
jg _parent
jmp _exit
_parent:
push p_msg
call printf
jmp _exit
_child:
push c_msg
call printf
jmp _exit
_exit:
push 0x1
mov eax, 1
push eax
int 0x80
ret
section .data
c_msg db "Printed from Child process",13,10,0
p_msg db "Printed from Parent process",13,10,0