Process.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* This Hello World demostrate a simple multithread program */
  2. #define DO_BENCH 0
  3. #include "api.h"
  4. #include "pal.h"
  5. #include "pal_debug.h"
  6. int main(int argc, char** argv) {
  7. int count = 0;
  8. #if DO_BENCH != 1
  9. pal_printf("In process: %s", argv[0]);
  10. for (int i = 1; i < argc; i++) {
  11. pal_printf(" %s", argv[i]);
  12. }
  13. pal_printf("\n");
  14. #endif
  15. if (argc == 1) {
  16. unsigned long time = DkSystemTimeQuery();
  17. char time_arg[24];
  18. snprintf(time_arg, 24, "%ld", time);
  19. const char* newargs[4] = {"Process", "0", time_arg, NULL};
  20. PAL_HANDLE proc = DkProcessCreate("file:Process", newargs);
  21. if (!proc)
  22. pal_printf("Can't create process\n");
  23. DkObjectClose(proc);
  24. DkThreadDelayExecution(30000000);
  25. } else {
  26. count = atoi(argv[1]);
  27. if (count < 100) {
  28. count++;
  29. char count_arg[8];
  30. snprintf(count_arg, 8, "%d", count);
  31. const char* newargs[4] = {"Process", count_arg, argv[2], NULL};
  32. PAL_HANDLE proc = DkProcessCreate("file:Process", newargs);
  33. if (!proc)
  34. pal_printf("Can't creste process\n");
  35. DkObjectClose(proc);
  36. } else {
  37. unsigned long end = DkSystemTimeQuery();
  38. unsigned long start = atol(argv[2]);
  39. pal_printf("wall time = %ld\n", end - start);
  40. }
  41. }
  42. DkProcessExit(0);
  43. return 0;
  44. }