Process.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* This Hello World demostrate a simple multithread program */
  2. #define DO_BENCH 0
  3. #include "pal.h"
  4. #include "pal_debug.h"
  5. #include "api.h"
  6. int main (int argc, char ** argv)
  7. {
  8. int count = 0;
  9. #if DO_BENCH != 1
  10. pal_printf("In process: %s", argv[0]);
  11. for (int i = 1 ; i < argc ; i++)
  12. pal_printf(" %s", argv[i]);
  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. }