Guest User

Untitled

a guest
Aug 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. is nice() used to change the thread priority or the process priority?
  2. void * thread_function1(void *arg)
  3. {
  4.  
  5. pid_t tid = syscall(SYS_gettid);
  6.  
  7. int ret = setpriority(PRIO_PROCESS, tid, -10);
  8. printf("tid of high priority thread %d , %dn",tid ,getpriority(PRIO_PROCESS,tid));
  9. while(1){
  10. printf("high priority ................n");
  11. }
  12.  
  13. }
  14.  
  15.  
  16. void * thread_function(void *arg)
  17. {
  18. pid_t tid = syscall(SYS_gettid);
  19. int ret = setpriority(PRIO_PROCESS, tid, 10);
  20. printf("tid of low priority thread %d , %d n",tid ,getpriority(PRIO_PROCESS,tid));
  21. while(1)
  22. {
  23.  
  24. printf("lower priorityn");
  25. }
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.  
  32. pthread_t id1;
  33. pthread_t id2;
  34.  
  35. pid_t pid = getpid();
  36. pid_t tid = syscall(SYS_gettid);
  37.  
  38. printf("main thread : pid = %d , tid = %d n" , pid, tid);
  39. pthread_create(&id1, NULL, thread_function1, NULL);
  40. pthread_create(&id1, NULL,thread_function, NULL);
  41.  
  42. pthread_join(id1, NULL);
  43. pthread_join(id2, NULL);
  44.  
  45.  
  46. }
Add Comment
Please, Sign In to add comment