Jun
Jun
@renwotao :smile:
@skyformat99 简单写个例子 ``` c #include #include #include #include int main(void) { pid_t pid; int status; printf("current pid = %d\n", getpid()); printf("fork one:\n"); if ((pid = fork()) < 0) fprintf(stderr, "fork...
@yetingsky |(- _-)|
将 iTerm2 替换成了 [Wezterm](https://wezterm.dev),在使用姿势不变的情况下,方便了我使用 lua 配置终端。
## thread_info task_struct 结构里面通过 CONFIG_THREAD_INFO_IN_TASK 宏来控制是否有 thread_info 成员结构, 我们再来看看 current_thread_info 宏: ```c // tags/v4.18 - include/linux/thread_info.h #ifdef CONFIG_THREAD_INFO_IN_TASK /* * For CONFIG_THREAD_INFO_IN_TASK kernels we need for the * definition of...
## state Linux 的几种状态定义在 include/linux/sched.h ```c // tags/v4.18 - include/linux/sched.h /* Used in tsk->state: */ #define TASK_RUNNING 0x0000 #define TASK_INTERRUPTIBLE 0x0001 #define TASK_UNINTERRUPTIBLE 0x0002 #define __TASK_STOPPED 0x0004 #define __TASK_TRACED 0x0008...
## pid & tgid 内核通过一个唯一的进程标识 PID 来标识每个 task_struct,处于某个线程组中的所有进程都有一个统一的线程组ID(TGID)。如果进程没有使用线程,则其 PID 和 TGID 相同。 ```c // tags/v4.18 - include/linux/sched.h struct task_struct { ... pid_t pid; pid_t tgid; ... } ``` 所以,我们在使用 getpid...
## parent & children & sibling Linux 的进程之间是有家族关系的。 每个进程都有一个父进程,相应的,每个进程也可以拥有零个或多个子进程。有同一个父进程的多个子进程之间称之为兄弟(sibling)进程。 ```c // tags/v4.18 - include/linux/sched.h struct task_struct { ... /* Real parent process: */ struct task_struct __rcu *real_parent; /* Recipient of...
# 0x01 栈帧的创建 ```c PyFrameObject* PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, PyObject *locals) { PyFrameObject *f = _PyFrame_New_NoTrack(tstate, code, globals, locals); if (f) _PyObject_GC_TRACK(f); return f; } PyFrameObject* _Py_HOT_FUNCTION _PyFrame_New_NoTrack(PyThreadState...
# 0x02 栈帧的执行 ```c PyObject* _Py_HOT_FUNCTION _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) { ... co = f->f_code; names = co->co_names; consts = co->co_consts; fastlocals = f->f_localsplus; freevars = f->f_localsplus + co->co_nlocals; first_instr...