Creating zombies Flashcards

1
Q

Processes are a very complex but important topic for…?

A

understanding how Linux works.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Most people think init is the mother of all processes, but that’s…?

A

not 100% correct.

(init is created by a process, which is called the idle process or swapper process. This process 0 actually is a kernel thread, which is created once the kernel enters its initialization phase. This process initializes data structures needed by the kernel and then creates a new kernel thread called process 1, which is the init process. Once this is done, process 0 executes cpu_idle(), henceforth it’s only executed by the scheduler when no other process is running.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

the new kernel thread shares all data structures with process 0.The following call of the init() function finishes initialization of the kernel and loads the init executable from disk into the current process invoking the execve() system call. Once the current process’s data structure is replaced with the new program, it becomes a regular process with….?

A

PID 1, known as process 1 or init, respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Linux distinguishes between…?

A

programs and processes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A process is a…?

A

slot for executing a program. Therefore, it’s a program in execution whereas a program is just a set of commands, which can be executed in a process. This also means that a process doesn’t have to belong to one specific program and actually, new processes are always created by copying it and replacing the program of the new child process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

New processes are children of…?

A

init, but also each other program can create its own children. A new program can be loaded into the new process by execve().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To span new processes, three main syscalls are used:

A
  • vfork(): This creates a copy of the current process, which shares all data structures with the parent process. The parent process itself is suspended until the child terminates. This syscall is hardly used because it blocks the parent process and can lead to data inconsistencies due to data sharing.
  • clone(): clone() creates a new “lightweight” process. Lightweight processes are Linux’s implementation of multithreading. With clone() a new process is created within a thread group. All processes within this group synchronize their data with each other and can be executed concurrently. Technically, lightweight processes have different PIDs, but due to the UNIX standard the PID returned by getpid() is the thread group ID which is equal to the PID of the first lightweight process in that group.
  • fork(): This syscall is mostly used for spawning new processes. Created children are more or less independent from their parent processes and have their own memory pages. fork() returns 0 if the current execution flow is in the child process otherwise the child’s PID.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Copying processes can be very expensive and therefore Linux uses….?

A

copy-on-write mechanisms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Once a new process is created, both, parent and child, share the same physical memory until one of them does…?

A

some modification.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The modified data is then written to…?

A

new physical memory pages, so the data remains unchanged for the second process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When a process has finished, it dies. That means that the kernel can…?

A

reuse all the memory used by that process. But the process does not vanish immediately. Its process descriptor (which contains information about this process) is still kept in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When a process dies, its process status is set to….?

A

EXIT_ZOMBIE and the parent is notified with a SIGCHLD signal that one of its children has died.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

. The zombie process will remain in memory until the parent reacts with a…?

A

wait4() or wait()/waitpid() syscall. Normally, this happens immediately, so the kernel knows that everything is fine, the parent has noticed and got all information it probably needs and the process can be cleaned up. Such a process is then set to EXIT_DEAD and cleaned up. But in some situation the parent doesn’t invoke a wait4() syscall. In that case the zombie process will stay in memory forever. Most of the time this happens due to faulty programming. You can examine zombie processes on your system with top. The number of zombies in memory is listed in the upper right corner. Another way is to use ps, which lists all processes running right at the moment. Zombie processes are marked with Z in the STAT column and have appended to their command listing. To list all zombies, run

ps axo user,pid,ppid,command,s | grep -w Z$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how to clean up zombie processes. Well, you can’t kill them since they’re already dead. There are only two ways to get rid of those…..?

A

The first is to send a SIGCHLD signal manually to the parent:

kill -CHLD

but in most cases this is not successful because the parent just ignores the signal. Another way is to make the zombie an orphan. Orphan processes are processes which don’t have parents anymore. Those processes are then assigned to init, which becomes their new parent. init regularly invokes wait() calls and cleans up all orphan processes. So when you kill the parent process, you kill all zombie children indirectly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Zombies shouldn’t be a big problem since they hardly consume memory because…?

A

only the process descriptor is kept in memory.
(However, if, e.g., a server program creates zombies, they could become a real danger if your system is flooded with requests.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Linux has a limited range of…?

A

PID numbers. The maximum PID on 32-bit systems is 32,767, so at 32,768 the system will reset the counter and try to allocate free numbers from the beginning.

17
Q

If all PIDs are used, no new…?

A

processes can be spawned.

18
Q

The zombie processes reserve all free PIDs, thus Linux can’t…?

A

recycle them

19
Q

On 64-bit systems zombies will take a little longer to…?

A

pinch all PIDs since the maximum number can be enlarged up to 2²², which is 4,194,304 (i.e., the maximum PID is 4,194,303).

The administrator can set the max PID by changing the value in /proc/sys/kernel/pid_max. By default this is set to 32,768, also on 64-bit systems.

20
Q

even though zombies are not a problem in most cases they can endanger your system stability when they…?

A

become too many. So keep them in mind and file bug reports if an application constantly produces zombies.