diff --git a/src/wrappers/posix/examples/forking.e b/src/wrappers/posix/examples/forking.e index 68e0eab..a4d282b 100644 --- a/src/wrappers/posix/examples/forking.e +++ b/src/wrappers/posix/examples/forking.e @@ -1,18 +1,23 @@ class FORKING +insert + MULTIPROCESSING + ANY create {ANY} make feature {ANY} make do - print("Father genertaing 5 childred%N") + print("Parent forking 5 children%N") create children.with_capacity(5); - 5.times(agent add_child) + 5.times(agent do children.add_last(create {MY_CHILD}) end) + children.for_each (agent {POSIX_PROCESS}.start) -- Eventually children.for_all(agent {MY_CHILD}.wait or join...) - print("Done%N") + children.for_each(agent {POSIX_PROCESS}.wait) + print("All processes finished%N") end children: FAST_ARRAY[POSIX_PROCESS] - add_child is - do - children.add_last(create {MY_CHILD}.start) - end + -- add_child is + -- do + -- children.add_last(create {MY_CHILD}.start) + -- end end diff --git a/src/wrappers/posix/examples/my_child.e b/src/wrappers/posix/examples/my_child.e index f7b548f..3bc6d53 100644 --- a/src/wrappers/posix/examples/my_child.e +++ b/src/wrappers/posix/examples/my_child.e @@ -1,11 +1,19 @@ class MY_CHILD inherit POSIX_PROCESS -create {ANY} start feature {ANY} - run - do - ("Greeting from child process (#"| process_id.out |").%N").print_on(std_output) - end + run + local r: INTEGER; gen: MINIMAL_RANDOM_NUMBER_GENERATOR + do + create gen.make + r := gen.last_integer(10) + ("Greeting from child process (###(1)); faking some work for #(2) seconds%N" # process_id.out # r.out).print_on(std_output) + r := sleep(r.to_natural_32).to_integer_32 + if r=0 then + ("(Child #(1)) Yahwn... I feel refreshed...%N" # process_id.out).print_on(std_output) + else + ("(Child #(2)) Ouch! Who awaked me after only #(2) seconds?%N" # process_id.out # &r).print_on(std_output) + end + end end - - + + diff --git a/src/wrappers/posix/library/externals/generated/fenv_externals.e b/src/wrappers/posix/library/externals/generated/fenv_externals.e index 1a303a5..faf1769 100644 --- a/src/wrappers/posix/library/externals/generated/fenv_externals.e +++ b/src/wrappers/posix/library/externals/generated/fenv_externals.e @@ -64,7 +64,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "fegetexcept" + feature_name: "fegetexcept()" }" end @@ -88,7 +88,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "fegetround" + feature_name: "fegetround()" }" end diff --git a/src/wrappers/posix/library/externals/generated/grp_externals.e b/src/wrappers/posix/library/externals/generated/grp_externals.e index 31201c2..b68f1ba 100644 --- a/src/wrappers/posix/library/externals/generated/grp_externals.e +++ b/src/wrappers/posix/library/externals/generated/grp_externals.e @@ -16,7 +16,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endgrent" + feature_name: "endgrent()" }" end @@ -52,7 +52,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getgrent" + feature_name: "getgrent()" }" end @@ -160,7 +160,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "setgrent" + feature_name: "setgrent()" }" end diff --git a/src/wrappers/posix/library/externals/generated/if_externals.e b/src/wrappers/posix/library/externals/generated/if_externals.e index 1ec33d3..bed3ece 100644 --- a/src/wrappers/posix/library/externals/generated/if_externals.e +++ b/src/wrappers/posix/library/externals/generated/if_externals.e @@ -40,7 +40,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "if_nameindex" + feature_name: "if_nameindex()" }" end diff --git a/src/wrappers/posix/library/externals/generated/locale_externals.e b/src/wrappers/posix/library/externals/generated/locale_externals.e index b5fb6b2..48d101c 100644 --- a/src/wrappers/posix/library/externals/generated/locale_externals.e +++ b/src/wrappers/posix/library/externals/generated/locale_externals.e @@ -40,7 +40,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "localeconv" + feature_name: "localeconv()" }" end diff --git a/src/wrappers/posix/library/externals/generated/mman_externals.e b/src/wrappers/posix/library/externals/generated/mman_externals.e index 6cfa0d6..c33436a 100644 --- a/src/wrappers/posix/library/externals/generated/mman_externals.e +++ b/src/wrappers/posix/library/externals/generated/mman_externals.e @@ -136,7 +136,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "munlockall" + feature_name: "munlockall()" }" end diff --git a/src/wrappers/posix/library/externals/generated/netdb_externals.e b/src/wrappers/posix/library/externals/generated/netdb_externals.e index 8d20c37..7937c4c 100644 --- a/src/wrappers/posix/library/externals/generated/netdb_externals.e +++ b/src/wrappers/posix/library/externals/generated/netdb_externals.e @@ -16,7 +16,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endhostent" + feature_name: "endhostent()" }" end @@ -28,7 +28,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endnetent" + feature_name: "endnetent()" }" end @@ -40,7 +40,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endnetgrent" + feature_name: "endnetgrent()" }" end @@ -52,7 +52,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endprotoent" + feature_name: "endprotoent()" }" end @@ -64,7 +64,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endservent" + feature_name: "endservent()" }" end @@ -232,7 +232,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "gethostent" + feature_name: "gethostent()" }" end @@ -316,7 +316,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getnetent" + feature_name: "getnetent()" }" end @@ -412,7 +412,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getprotoent" + feature_name: "getprotoent()" }" end @@ -484,7 +484,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getservent" + feature_name: "getservent()" }" end diff --git a/src/wrappers/posix/library/externals/generated/pthread_externals.e b/src/wrappers/posix/library/externals/generated/pthread_externals.e index 96f6c75..edb7de2 100644 --- a/src/wrappers/posix/library/externals/generated/pthread_externals.e +++ b/src/wrappers/posix/library/externals/generated/pthread_externals.e @@ -616,7 +616,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "pthread_getconcurrency" + feature_name: "pthread_getconcurrency()" }" end @@ -1192,7 +1192,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "pthread_self" + feature_name: "pthread_self()" }" end @@ -1372,7 +1372,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "pthread_testcancel" + feature_name: "pthread_testcancel()" }" end @@ -1408,7 +1408,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "pthread_yield" + feature_name: "pthread_yield()" }" end diff --git a/src/wrappers/posix/library/externals/generated/pwd_externals.e b/src/wrappers/posix/library/externals/generated/pwd_externals.e index 0d284ed..955fa7e 100644 --- a/src/wrappers/posix/library/externals/generated/pwd_externals.e +++ b/src/wrappers/posix/library/externals/generated/pwd_externals.e @@ -16,7 +16,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endpwent" + feature_name: "endpwent()" }" end @@ -64,7 +64,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getpwent" + feature_name: "getpwent()" }" end @@ -148,7 +148,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "setpwent" + feature_name: "setpwent()" }" end diff --git a/src/wrappers/posix/library/externals/generated/sched_externals.e b/src/wrappers/posix/library/externals/generated/sched_externals.e index dd43708..6c61709 100644 --- a/src/wrappers/posix/library/externals/generated/sched_externals.e +++ b/src/wrappers/posix/library/externals/generated/sched_externals.e @@ -124,7 +124,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "sched_yield" + feature_name: "sched_yield()" }" end diff --git a/src/wrappers/posix/library/externals/generated/signal_externals.e b/src/wrappers/posix/library/externals/generated/signal_externals.e index 5e4a5a3..36bfd1b 100644 --- a/src/wrappers/posix/library/externals/generated/signal_externals.e +++ b/src/wrappers/posix/library/externals/generated/signal_externals.e @@ -198,7 +198,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "siggetmask" + feature_name: "siggetmask()" }" end diff --git a/src/wrappers/posix/library/externals/generated/stat_externals.e b/src/wrappers/posix/library/externals/generated/stat_externals.e index a13cee0..b41c851 100644 --- a/src/wrappers/posix/library/externals/generated/stat_externals.e +++ b/src/wrappers/posix/library/externals/generated/stat_externals.e @@ -116,7 +116,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getumask" + feature_name: "getumask()" }" end diff --git a/src/wrappers/posix/library/externals/generated/syslog_externals.e b/src/wrappers/posix/library/externals/generated/syslog_externals.e index 7caaf41..99349cf 100644 --- a/src/wrappers/posix/library/externals/generated/syslog_externals.e +++ b/src/wrappers/posix/library/externals/generated/syslog_externals.e @@ -16,7 +16,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "closelog" + feature_name: "closelog()" }" end diff --git a/src/wrappers/posix/library/externals/generated/unistd_externals.e b/src/wrappers/posix/library/externals/generated/unistd_externals.e index a557d6c..81c2f72 100644 --- a/src/wrappers/posix/library/externals/generated/unistd_externals.e +++ b/src/wrappers/posix/library/externals/generated/unistd_externals.e @@ -208,7 +208,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endusershell" + feature_name: "endusershell()" }" end @@ -420,7 +420,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "fork" + feature_name: "fork()" }" end @@ -480,7 +480,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "get_current_dir_name" + feature_name: "get_current_dir_name()" }" end @@ -516,7 +516,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getdtablesize" + feature_name: "getdtablesize()" }" end @@ -528,7 +528,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getegid" + feature_name: "getegid()" }" end @@ -540,7 +540,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "geteuid" + feature_name: "geteuid()" }" end @@ -552,7 +552,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getgid" + feature_name: "getgid()" }" end @@ -576,7 +576,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "gethostid" + feature_name: "gethostid()" }" end @@ -600,7 +600,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getlogin" + feature_name: "getlogin()" }" end @@ -624,7 +624,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getpagesize" + feature_name: "getpagesize()" }" end @@ -661,7 +661,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getpgrp" + feature_name: "getpgrp()" }" end @@ -673,7 +673,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getpid" + feature_name: "getpid()" }" end @@ -685,7 +685,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getppid" + feature_name: "getppid()" }" end @@ -733,7 +733,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getuid" + feature_name: "getuid()" }" end @@ -745,7 +745,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getusershell" + feature_name: "getusershell()" }" end @@ -877,7 +877,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "pause" + feature_name: "pause()" }" end @@ -1141,7 +1141,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "setpgrp" + feature_name: "setpgrp()" }" end @@ -1201,7 +1201,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "setsid" + feature_name: "setsid()" }" end @@ -1225,7 +1225,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "setusershell" + feature_name: "setusershell()" }" end @@ -1285,7 +1285,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "sync" + feature_name: "sync()" }" end @@ -1405,7 +1405,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "ttyslot" + feature_name: "ttyslot()" }" end @@ -1465,7 +1465,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "vfork" + feature_name: "vfork()" }" end @@ -1477,7 +1477,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "vhangup" + feature_name: "vhangup()" }" end diff --git a/src/wrappers/posix/library/externals/generated/utmpx_externals.e b/src/wrappers/posix/library/externals/generated/utmpx_externals.e index 09d7410..f658e2a 100644 --- a/src/wrappers/posix/library/externals/generated/utmpx_externals.e +++ b/src/wrappers/posix/library/externals/generated/utmpx_externals.e @@ -16,7 +16,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "endutxent" + feature_name: "endutxent()" }" end @@ -52,7 +52,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "getutxent" + feature_name: "getutxent()" }" end @@ -100,7 +100,7 @@ feature {} -- External calls alias "{ location: "." module_name: "plugin" - feature_name: "setutxent" + feature_name: "setutxent()" }" end diff --git a/src/wrappers/posix/library/multiprocessing.e b/src/wrappers/posix/library/multiprocessing.e index 050b612..17595c6 100644 --- a/src/wrappers/posix/library/multiprocessing.e +++ b/src/wrappers/posix/library/multiprocessing.e @@ -1,6 +1,8 @@ deferred class MULTIPROCESSING -- Facilities for multiprocessing -insert UNISTD_EXTERNALS +insert + UNISTD_EXTERNALS + WAIT_EXTERNALS feature {ANY} processors_count: INTEGER -- Number of processors available in the machine @@ -17,5 +19,19 @@ feature {ANY} Result:=getpid end + parent_process_id: INTEGER_32 + do + Result:=getppid + end + + wait_any_process: INTEGER_32 + -- Wait for any child process to terminate + do + Result := wait($last_result) + end + + last_result: INTEGER_32 + -- The exit status of the last terminated children + end diff --git a/src/wrappers/posix/library/posix_process.e b/src/wrappers/posix/library/posix_process.e index 907c7f5..8fb0919 100644 --- a/src/wrappers/posix/library/posix_process.e +++ b/src/wrappers/posix/library/posix_process.e @@ -1,49 +1,102 @@ deferred class POSIX_PROCESS - -- A process as described in the POSIX standard. - - -- Commands and queries of this class are loosely modelled after the - -- multiprocessing API of Python - -- (http://docs.python.org/library/multiprocessing.html). -insert - ERRNO - MULTIPROCESSING -feature {ANY} - child_process_id: like process_id - -- The process ID of the child process - - is_child: BOOLEAN - do - Result := child_process_id=0 - end - - start - -- Create the new process and make it run - -- TODO:require not_invoked_multiple_times: not - do - child_process_id := fork - if child_process_id = 0 then run; die_with_code(exit_success_code) -- executed by the child process - elseif child_process_id = -1 then -- there is an error - if errno = eagain then not_yet_implemented - elseif errno = enomem then not_yet_implemented - else not_yet_implemented -- unknown error code - end - else -- nothing, this is executed by the father process - end - end - - run - -- The command that will be executed in the child process - deferred - end - - terminate - -- Send SIGTERM signal to Current process - do - not_yet_implemented - end - - is_running: BOOLEAN - do - not_yet_implemented - end + -- A process as described in the POSIX standard. + -- Commands and queries of this class are loosely modelled after the + -- multiprocessing API of Python + -- (http://docs.python.org/library/multiprocessing.html). + +insert + ERRNO + MULTIPROCESSING + rename + wait as posix_wait + end + EXCEPTIONS + +feature {ANY} + child_process_id: like process_id + + is_child: BOOLEAN + do + Result := child_process_id /= 0 + end + + is_parent: BOOLEAN + do + Result := child_process_id = -1 + end + + is_started: BOOLEAN + do + Result := child_process_id /= 0 + end + + not_started: BOOLEAN + do + Result := child_process_id = 0 + end + + start + -- Create the new process and make it run + require + not_started + local + err: like errno + do + child_process_id := fork + err := errno + if child_process_id = 0 then + -- executed by the child process + run + die_with_code(exit_success_code) + elseif child_process_id = -1 then + -- something went wrong + + -- This if clause should be an inspect but eagain and enomem are + -- not recognized as constants + if err=eagain then + raise_exception(No_more_memory) + elseif err=enomem then + raise_exception(No_more_memory) + end + else + -- executed by the father process + debug + std_error.put_line("I'm the parent process " + process_id.out) + end + end + end + + run + -- The command that will be executed in the child process + deferred + end + + wait + -- Wait until Current has terminated + -- + -- TODO: add support for options of Posix's waitpid + local pid_t: like process_id + do + pid_t := waitpid(child_process_id,$status,0) + end + + terminate + -- Send SIGTERM signal to the child process. + require is_parent + do + if is_parent then + not_yet_implemented + end + end + +feature {ANY} -- Status queries + + is_running: BOOLEAN + do + not_yet_implemented + end + + status: INTEGER + -- + end -- class POSIX_PROCESS