Reputation: 486
I have recently read some papers on the Linux thread scheduler (some simple introductions on the subject). In those the different states a linux thread can have were explained (ready, running, waiting, ...).
I'm now wondering if calling a sleep
-like method (sleep()
in C, this_thread::sleep_for
in C++, Thread.Sleep()
in C#, etc) sets the thread's state at OS level. Even though I guess it should, I just want to be sure, since I'm a little confused. Thanks
Upvotes: 0
Views: 437
Reputation: 486
According to what suggested Ulrich Eckhardt, I tried it by myself:
#include <unistd.h>
int main() {
sleep(60);
return 0;
}
$ gcc test.c -o test
$ ./test &
$ top -H -p $(pidof test)
And among other stuff, I got:
Threads: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
So indeed calling a sleep
-like function sets the OS level thread's state to 'sleeping'.
Upvotes: 1