Linus Torvalds stated in a kernel mailing list post in 1996 that “both threads and processes are treated as a "context'context of execution"execution'", which is "just a conglomerate of all of the state of that CoE.... includes things like CPU state, MMU state, permissions, and various communication states (open files, signal handlers, etc)".
Linus Torvalds stated in a kernel mailing list post in 1996 that “both threads and processes are treated as a "context of execution", which is "just a conglomerate of all of the state of that CoE.... includes things like CPU state, MMU state, permissions, and various communication states (open files, signal handlers, etc)".
Linus Torvalds stated in a kernel mailing list post in 1996 that “both threads and processes are treated as a 'context of execution'", which is "just a conglomerate of all of the state of that CoE.... includes things like CPU state, MMU state, permissions, and various communication states (open files, signal handlers, etc)".
Linus Torvalds stated in a kernel mailing list post in 1996 that “both threads and processes are treated as a "context of execution", which is "just a conglomerate of all of the state of that CoE.... includes things like CPU state, MMU state, permissions, and various communication states (open files, signal handlers, etc)".
// simple program to create threads that simply sleep // compile in debian jessie with apt-get install build-essential // and then g++ -O4 -Wall -std=c++0x -pthread threads2.cpp -o threads2 #include <string> #include <iostream> #include <thread> #include <chrono> // how many seconds will the threads sleep for? #define SLEEPTIME 100 // how many threads should I start? #define NUM_THREADS 25 using namespace std; // The function we want to execute on the new thread. void threadSleeper(int threadid){ // output what number thread we've created cout << "task: " << threadid << "\n"; // take a nap and sleep for a while std::this_thread::sleep_for(std::chrono::seconds(SLEEPTIME)); } void main(){ // create an array of thread handles thread threadArr[NUM_THREADS]; for(int i=0;i<NUM_THREADS;i++){ // spawn the threads threadArr[i]=thread(threadSleeper, i); } for(int i=0;i<NUM_THREADS;i++){ // wait for the threads to finish threadArr[i].join(); } // program done cout << "Done\n"; return; } As you can see this program will spawn 25 threads at once, each one of which will sleep for 100 seconds and then join the main program again. After all 25 threads have rejoined the program, the program is done and will exit.
Using top you'll be able to see 25 instances of the "threads2" program. But kidna boring. The output of ps auwx is even less interesting... BUT ps -eLf gets kinda exciting.
UID PID PPID LWP C NLWP STIME TTY TIME CMD debian 689 687 689 0 1 14:52 ? 00:00:00 sshd: debian@pts/0 debian 690 689 690 0 1 14:52 pts/0 00:00:00 -bash debian 6217 690 6217 0 1 15:04 pts/0 00:00:00 screen debian 6218 6217 6218 0 1 15:04 ? 00:00:00 SCREEN debian 6219 6218 6219 0 1 15:04 pts/1 00:00:00 /bin/bash debian 6226 6218 6226 0 1 15:04 pts/2 00:00:00 /bin/bash debian 6232 6219 6232 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6233 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6234 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6235 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6236 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6237 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6238 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6239 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6240 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6241 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6242 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6243 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6244 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6245 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6246 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6247 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6248 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6249 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6250 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6251 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6252 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6253 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6254 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6255 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6256 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6232 6219 6257 0 26 15:04 pts/1 00:00:00 ./threads2 debian 6260 6226 6260 0 1 15:04 pts/2 00:00:00 ps -eLf You can see here all 26 CoEs that the thread2 program has created. They all share the same process ID (PID) and parent process ID (PPID) but each one has a different LWP ID (light weight process), and the number of LWPs (NLWP) indicates there are 26 CoEs – the main program and the 25 threads spawned by it.