Process.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. pal_printf("Creating process\n");
  36. children[i] = DkProcessCreate("file:Process", 0, args);
  37. if (children[i]) {
  38. pal_printf("Process created %d\n", i + 1);
  39. DkStreamRead(children[i], 0, 20, buffer4, NULL, 0);
  40. }
  41. }
  42. pal_printf("Broadcasting message\n");
  43. ret = DkStreamWrite(pal_control.broadcast_stream, 0, 20, buffer1, NULL);
  44. if (ret > 0)
  45. pal_printf("Broadcast Write OK\n");
  46. for (int i = 0 ; i < 3 ; i++)
  47. if (children[i]) {
  48. ret = DkStreamRead(children[i], 0, 20, buffer3, NULL, 0);
  49. if (ret > 0)
  50. pal_printf("Process Read 1: %s\n", buffer3);
  51. ret = DkStreamWrite(children[i], 0, 20, buffer2, NULL);
  52. if (ret > 0)
  53. pal_printf("Process Write 2 OK\n");
  54. }
  55. }
  56. return 0;
  57. }