CURPROC(9)

CURPROC(9) | Kernel Developer's Manual | CURPROC(9)

# NAME

`curproc`, `curcpu`, `curlwp` —
current process, processor, and LWP

# SYNOPSIS

`#include <sys/proc.h>`

struct cpu_info *
`curcpu`(void);

struct proc *curproc;
struct lwp *curlwp;

# DESCRIPTION

The following macros retrieve the current CPU, process, and thread (lightweight process, or LWP), respectively:

`curcpu`()
  Returns a pointer to the struct cpu_info structure representing the CPU that the code calling it is running on.

  The value of `curcpu`() is unstable and may be stale as soon as it is read unless the caller prevents preemption by raising the IPL (spl(9), mutex(9)), by disabling preemption (kpreempt_disable(9)), or by binding the thread to its CPU (curlwp_bind(9)).

`curproc`
  Yields a pointer to the struct proc structure representing the currently running process.

  The value of `curproc` is stable and does not change during execution except in machine-dependent logic to perform context switches, so it works like a global constant, not like a stateful procedure.

`curlwp`
  Yields a pointer to the struct lwp structure representing the currently running thread.

  The value of `curlwp` is stable and does not change during execution except in machine-dependent logic to perform context switches, so it works like a global constant, not like a stateful procedure.

# SOURCE REFERENCES

The `curcpu`() macro is defined in the machine-independent machine/cpu.h.

The `curproc` macro is defined in sys/lwp.h.

The `curlwp` macro has a machine-independent definition in sys/lwp.h, but it may be overridden by machine/cpu.h, and must be overridden on architectures supporting multiprocessing and kernel preemption.

# SEE ALSO

cpu_number(9), proc_find(9)

July 1, 2010 | NetBSD 10.0