Proccess states (TASK_RUNNNING, TASK_INTERRUPTIBLE..etc) in linux kernel

One of the ‘task_struct’ field is ‘state‘ which says the ‘state’ of this process..

I see there are 2 types of ‘states’, it can be either ‘state’ or ‘exit_state’

task->state is about ‘runnability‘..

task->exit_state is about ‘task exiting’

One of the flags in ‘state’ will be set and ‘state’ flags are mutually exclusive..

task->state flags are:

#define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 #define TASK_UNINTERRUPTIBLE 2 #define __TASK_STOPPED 4 #define __TASK_TRACED 8 #define TASK_DEAD 64 #define TASK_WAKEKILL 128 #define TASK_WAKING 256

task->exit_state flags are:

#define EXIT_ZOMBIE 16 #define EXIT_DEAD 32

ABOUT task->state runnability flags:

*) TASK_RUNNNING

A process with ‘TASK_RUNNING’ state means that the process is runnable, and it is either currently running or on a run queue waiting to run. This is the only possible state for a process executing in userspace. it can also apply to a process in kernel space that is actively running. That said, this process is either executing on CPU or waiting for the CPU to execute.

*) TASK_INTERRUPTIBLE

The process is suspended (sleeping) until some condition becomes true. Events like hardware interrupt, signal delivery, released system resources can wake up the process and change the status back to TASK_RUNNING. Processes in idle mode (ie not performing any task) should be in this state.

*) TASK_UNINTERRUPTIBLE

Like “TASK_INTERRUPTIBLE”, a signal delivery is not honored with the process is in TASK_UNINTERRPTIBLE” state. An example would be a process performing an atomic write operation.

The TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE indicate that the task is a wait state. Tasks at TASK_INTERRUPTIBLE state can be interrupted and wake up by an interrupt or a signal and will be returning to state TASK_RUNNING. Tasks at TASK_UNINTERRUPTIBALE must be explicitly waked up by an event. e.x. a task waiting for the data transferred from block dev to buffer.

TASK_INTERRUPTIBLE OR UNINTERRUPTIBLE processes are in wait queues. The task_structs which hold states either of these can be in wait queues..

struct __wait_queue_head { spinlock_t lock; struct list_head task_list; };

typedef struct __wait_queue_head wait_queue_head_t;

These are the processes waiting for an event to finish, system resource to be released, fixed interval of time to be
elapsed..

* ) TASK_STOPPED :

Process execution has been stopped; The process received any of ‘SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU’ signals.

SIGSTOP 17,19,23 Stop Stop process

SIGTSTP 18,20,24 Stop Stop typed at tty

SIGTTIN 21,21,26 Stop tty input for background process

SIGTTOU 22,22,27 Stop tty output for background process

*) TASK_TRACED

The subjected process has been traced by a debugger. Execution has been stopped by a debugger (ex: gdb ): When debugged each signal may put the process in this state.

2 possible states in task->exit_state.

1) EXIT_ZOMBIE:

Zombie processes are also called “defunct” processes in the system. Those are processes whose execution is completed, but the parent is not aware of it or parent didn’t reap its child, so it holds an entry in process table. It will not waste any other resources in the system. The only resource it wastes is the entry in the process table. It becomes an issue only when we/system reaches the situation: “The total no of processes running in the system is equal to the max limit of number of processes”. Then we may worry about them. The main chance for zombie creation is when a parent didn’t wait() for this child, in other words crappy application developers can generate a zombie process.

On the other hand, if the parent dies first, init (process 1) inherits the child and becomes its parent.

2) EXIT_DEAD:

This state comes to a picture when there is a transition happening from EXIT_ZOMBIE. The process is being removed by the system as the parent called wait ().

I hope it helps.

Examine/display memory and register in gdb

This is going to be a small demonstration or ‘tip’ to analyze registers and memory via gdb when debugging a program. These commands are pretty much useful when debugging a program. It has its own use cases.

Examine registers:

$info registers is the command which can be used to see current register values at the moment from gdb prompt. Below command can be used as a short cut to view registers:

(gdb) i r rax 0x1 1 rbx 0x7fff955a9df0 140735699131888 rcx 0xffffffffffffffff -1 rdx 0x7fff955a9e70 140735699132016 rsi 0x7fff955a9df0 140735699131888 rdi 0x16 22 rbp 0x7fff955a9e70 0x7fff955a9e70 rsp 0x7fff955a9dc0 0x7fff955a9dc0 r8 0x7fff955a9dd0 140735699131856 r9 0x1 1 r10 0x7fff955a9ef0 140735699132144 r11 0x293 659 r12 0x7fff955a9ef0 140735699132144 r13 0x0 0 r14 0x1 1 r15 0x0 0 rip 0x37e78da373 0x37e78da373 eflags 0x293 [ CF AF SF IF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0

Register information can be fetched individually . For ex: “Stack pointer” and “Instruction pointer” information can be fetched by:

(gdb) i r $sp sp: 0x7fff955a9dc0 (gdb) i r $rip rip 0x37e78da373 0x37e78da373 (gdb)

Examining memory :

This is pretty much useful when debugging a program:

“x” is the command which can be used for the same purpose.. The general format of ‘x’ command as shown here.

(gdb) help x

Examine memory: x/FMT ADDRESS.

ADDRESS is an expression for the memory address to examine. FMT is a repeat count followed by a format letter and a size letter. Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address), i(instruction), c(char) and s(string). Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes). The specified number of objects of the specified size are printed according to the format.

Defaults for format and size letters are those previously used. The default count is 1. The default address is the following the last thing printed with this command or “print”. (gdb)

In short :

Formats: o – octal d – decimal x – hexadecimal u – unsigned integer s – string t – binary

Units: b – byte h – half w – word g – double word

Example use of ‘x’ command:

“3” words of memory ‘above’ stack pointer can be displayed by:

But why I used “above” here? ‘Ans’: It is homework/assignment for you 🙂

(gdb) x/3xw $sp 0x7fff955a9dc0: 0x00000000 0x00000000 0x0041ecb1 (gdb)

“2” machine instructions from 0x37e78da373/eip

(gdb) x/2i 0x37e78da373 => 0x37e78da373 : mov (%rsp),%rdi 0x37e78da377 : mov %rax,%rdx (gdb)

To display a string you can use: ‘ I selected a random address’, so it may not give a human-readable example string as output.

(gdb) x/s 0x0041ecb1 0x41ecb1: “A\211\307藟\001” (gdb)

I hope this helps.

what is "sourcing" in unix/linux shell..

Let me explore “sourcing” in a UNIX/LINUX shell by few words. I have seen the usage of “sourcing” for a long time in my linux systems. Today I thought of making it familiar to my friends by this blog.. [humble@humble ]$ cat /etc/rc5.d/S07iscsid |head -n 30|grep -v “#” . /etc/rc.d/init.d/functions exec=/sbin/iscsid prog=iscsid config=/etc/iscsi/iscsid.conf lockfile=/var/lock/subsys/$prog [humble@humble …

Read more

"GIT" What, how , ..etc ?

GIT ? “Git is distributed version control system focused on speed, effectivity and real-worldusability on large projects.” The above snip can be found here at “http://git-scm.com/about”… I dont know how many people are using “git” with their daily work.. But I know almost all open source projects are moving to “git” model Or almost done.. …

Read more

Install Fully virtualized guest on an ITANIUM system

To install a fully virtualized guest on an Itanium Red Hat Enterprise Linux system, first ensure that “xen-ia64-guest-firmware” package is installed on the host. After creating the guest, either through virt-manager or using virt-install, the guest will present an EFI shell. In order to begin the installation, enter mount fs0. This will make files available …

Read more

How can I increase a virtual image disk space if it is created on a file image

This is a very useful method in your real life.. I have come across to increase the space in virtual machine when it created on a file image .. You can try any of the below to increase the space depending on the virtual guest’s storage .. That being said , it is possible to …

Read more