How Linux handles threads and process scheduling

前端 未结 3 1253
南方客
南方客 2020-11-29 20:28

I\'m trying to understand how Linux handles process scheduling and thread scheduling. I read that Linux can schedule both processes and threads.

Does Linux have a th

相关标签:
3条回答
  • 2020-11-29 21:10

    The Linux kernel scheduler is actually scheduling tasks, and these are either threads or (single-threaded) processes.

    So a task (a task_struct inside the kernel), in the context of the scheduler, is the thing being scheduled, and can be some kernel thread like kworker or kswapd, some user thread of a multi-threaded process (like firefox), or the single-thread of a single-threaded process (like bash), identified with that single-threaded process.

    A process is a non-empty finite set (sometimes a singleton) of threads sharing the same virtual address space (and other things like file descriptors, working directory, etc etc...). See also credentials(7), capabilities(7) etc....

    Threads on Linux are kernel threads (in the sense of being managed by the kernel, which also creates its own threads), created by the Linux specific clone syscall (which can also be used to create processes on Linux). The pthread_create function is probably built (on Linux) above clone inside NPTL and Gnu Libc (which integrated NPTL on Linux) and musl-libc.

    0 讨论(0)
  • 2020-11-29 21:21

    Kernel threads under Linux are implemented as processes that share resources. The scheduler does not differentiate between a thread and a process

    See here for more information: http://www.linuxquestions.org/linux/articles/Technical/Linux_Kernel_Thread

    0 讨论(0)
  • 2020-11-29 21:21

    Under LINUX there is no concept of threads,to make LINUX POSIX complaint thread is nothing but another process.when you try to get a process id it would display the leader process id under any thread. For more details try to refer this book "Understanding LINUX kernel".Hope

    0 讨论(0)
提交回复
热议问题