execd.js 971 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. Execd - Execute after Detach
  3. This script demonstrate the execd function call
  4. USE WITH CAUTION
  5. Here is a few tips for you to develop a script containing execd
  6. 1. Do not execute self script unless you are sure about what you are doing
  7. 2. Instant / short task should be put in the main script while long running
  8. task should be called with execd instead
  9. */
  10. function parent(){
  11. console.log("Parent starting Child Process...")
  12. //Execute this script file in child mode with payload string
  13. execd("execd.js", "Payload to child")
  14. console.log("Parent Completed")
  15. }
  16. function child(){
  17. //Print the payload string
  18. console.log("Receiving payload from parent: " + PARENT_PAYLOAD)
  19. //Delay (emulate processing something)
  20. delay(5000);
  21. console.log("Child finished")
  22. }
  23. if (typeof PARENT_DETACHED == 'undefined'){
  24. //This is parent
  25. parent();
  26. }else if (PARENT_DETACHED == true){
  27. //This is child
  28. child();
  29. }