12

A PCB or process control block, is defined like this on Wikipedia

Process Control Block (PCB, also called Task Controlling Block,[1] Task Struct, or Switchframe) is a data structure in the operating system kernel containing the information needed to manage a particular process. The PCB is "the manifestation of a process in an operating system

and its duty is:

Process identification data
Processor state data
Process control data

So where can the PCB of a process be found?

1

2 Answers 2

18

In the Linux kernel, each process is represented by a task_struct in a doubly-linked list, the head of which is init_task (pid 0, not pid 1). This is commonly known as the process table.

In user mode, the process table is visible to normal users under /proc. Taking the headings for your question:

  • Process identification data is the process ID (which is in the path /proc/<process-id>/...), the command line (cmd), and possibly other attributes depending on your definition of 'identification'.

  • Process state data includes scheduling data (sched, stat and schedstat), what the process is currently waiting on (wchan), its environment (environ) etc.

  • Process control data could be said to be its credentials (uid_map) and resource limits (limits).

So it all depends how you define your terms... but in general, all data about a process can be found in /proc.

4
  • "the head of which is init_task (pid 0, not pid 1)" There's no such thing as init_task. It's init, and its pid is 1, not 0 (confirmed via pidof init).
    – AleksandrH
    Sep 15, 2018 at 14:42
  • 1
    @AleksandrH init_task is a kernel structure and not a process. It points to the idle task which is internally represented by pid 0. init_task and init are completely different things.
    – Flup
    Sep 15, 2018 at 15:39
  • And yet pid is only for processes...
    – AleksandrH
    Sep 15, 2018 at 16:38
  • 2
    @AleksandrH Read init/init_task.c in the kernel source tree (github.com/torvalds/linux/blob/master/init/init_task.c).
    – Flup
    Sep 15, 2018 at 16:39
0

PCB in linux is part of thread_info struct

struct thread_info {
struct pcb_struct   pcb;        /* palcode state */

struct task_struct  *task;      /* main task structure */
unsigned int        flags;      /* low level flags */
unsigned int        ieee_state; /* see fpu.h */

mm_segment_t        addr_limit; /* thread address space */
unsigned        cpu;        /* current CPU */
int         preempt_count; /* 0 => preemptable, <0 => BUG */
unsigned int        status;     /* thread-synchronous flags */

int bpt_nsaved;
unsigned long bpt_addr[2];      /* breakpoint handling  */
unsigned int bpt_insn[2];};


struct pcb_struct {
unsigned long ksp; - Kernel Stack Pointer
unsigned long usp; - User stack Pointer
unsigned long ptbr; - Page table address
unsigned int pcc;
unsigned int asn;
unsigned long unique;
unsigned long flags;
unsigned long res1, res2;};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.