Process.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "api.h"
  2. #include "pal.h"
  3. #include "pal_debug.h"
  4. int main(int argc, char** argv, char** envp) {
  5. char buffer1[20] = "Hello World 1", buffer2[20] = "Hello World 2";
  6. char buffer3[20], buffer4[20];
  7. int ret;
  8. if (argc > 1 && !memcmp(argv[1], "Child", 6)) {
  9. pal_printf("Child Process Created\n");
  10. /* check manifest name */
  11. char manifest[30] = "";
  12. DkStreamGetName(pal_control.manifest_handle, manifest, 30);
  13. pal_printf("Loaded Manifest: %s\n", manifest);
  14. /* check arguments */
  15. pal_printf("# of Arguments: %d\n", argc);
  16. for (int i = 0; i < argc; i++) {
  17. pal_printf("argv[%d] = %s\n", i, argv[i]);
  18. }
  19. DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
  20. ret = DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
  21. if (ret > 0)
  22. pal_printf("Process Write 1 OK\n");
  23. ret = DkStreamRead(pal_control.parent_process, 0, 20, buffer4, NULL, 0);
  24. if (ret > 0)
  25. pal_printf("Process Read 2: %s\n", buffer4);
  26. } else {
  27. PAL_STR args[3] = {"Process", "Child", 0};
  28. PAL_HANDLE children[3];
  29. for (int i = 0; i < 3; i++) {
  30. pal_printf("Creating process\n");
  31. children[i] = DkProcessCreate("file:Process", args);
  32. if (children[i]) {
  33. pal_printf("Process created %d\n", i + 1);
  34. DkStreamRead(children[i], 0, 20, buffer4, NULL, 0);
  35. }
  36. }
  37. for (int i = 0; i < 3; i++)
  38. if (children[i]) {
  39. ret = DkStreamRead(children[i], 0, 20, buffer3, NULL, 0);
  40. if (ret > 0)
  41. pal_printf("Process Read 1: %s\n", buffer3);
  42. ret = DkStreamWrite(children[i], 0, 20, buffer2, NULL);
  43. if (ret > 0)
  44. pal_printf("Process Write 2 OK\n");
  45. }
  46. }
  47. return 0;
  48. }