Process.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include "pal.h"
  4. #include "pal_debug.h"
  5. #include "api.h"
  6. int main (int argc, char ** argv, char ** envp)
  7. {
  8. char buffer1[20] = "Hello World 1", buffer2[20] = "Hello World 2";
  9. char buffer3[20], buffer4[20], buffer5[20];
  10. int ret;
  11. if (argc > 1 && !memcmp(argv[1], "Child", 6)) {
  12. pal_printf("Child Process Created\n");
  13. /* check manifest name */
  14. char manifest[30] = "";
  15. DkStreamGetName(pal_control.manifest_handle, manifest, 30);
  16. pal_printf("Loaded Manifest: %s\n", manifest);
  17. /* check arguments */
  18. pal_printf("# of Arguments: %d\n", argc);
  19. for (int i = 0 ; i < argc ; i++)
  20. pal_printf("argv[%d] = %s\n", i, argv[i]);
  21. DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
  22. ret = DkStreamRead(pal_control.broadcast_stream, 0, 20, buffer5, NULL, 0);
  23. if (ret > 0)
  24. pal_printf("Broadcast Read: %s\n", buffer5);
  25. ret = DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
  26. if (ret > 0)
  27. pal_printf("Process Write 1 OK\n");
  28. ret = DkStreamRead(pal_control.parent_process, 0, 20, buffer4, NULL, 0);
  29. if (ret > 0)
  30. pal_printf("Process Read 2: %s\n", buffer4);
  31. } else {
  32. PAL_STR args[3] = { "Process", "Child", 0 };
  33. PAL_HANDLE children[3];
  34. for (int i = 0 ; i < 3 ; i++) {
  35. children[i] = DkProcessCreate("file:Process", 0, args);
  36. if (children[i])
  37. DkStreamRead(children[i], 0, 20, buffer4, NULL, 0);
  38. }
  39. ret = DkStreamWrite(pal_control.broadcast_stream, 0, 20, buffer1, NULL);
  40. if (ret > 0)
  41. pal_printf("Broadcast Write OK\n");
  42. for (int i = 0 ; i < 3 ; i++)
  43. if (children[i]) {
  44. ret = DkStreamRead(children[i], 0, 20, buffer3, NULL, 0);
  45. if (ret > 0)
  46. pal_printf("Process Read 1: %s\n", buffer3);
  47. ret = DkStreamWrite(children[i], 0, 20, buffer2, NULL);
  48. if (ret > 0)
  49. pal_printf("Process Write 2 OK\n");
  50. }
  51. }
  52. return 0;
  53. }