Skip to content

Commit

Permalink
Format documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Nov 17, 2023
1 parent 83f38fd commit 1e91a9d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 49 deletions.
60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,51 @@

[![Build](https://img.shields.io/github/actions/workflow/status/orhun/zps/ci.yml?color=black&style=flat-square)](https://github.com/orhun/zps/actions?query=workflow%3A%22Continuous+Integration%22)
[![Docker Build](https://img.shields.io/github/actions/workflow/status/orhun/zps/docker.yml?color=black&style=flat-square&label=docker)](https://github.com/orhun/zps/actions?query=workflow%3A%22Docker+Automated+Builds%22)
[![Codacy](https://img.shields.io/codacy/grade/3d40a551806b4c788befba6d2920675b.svg?color=black&style=flat-square)](https://www.codacy.com/manual/orhun/zps?utm_source=github.com&utm_medium=referral&utm_content=orhun/zps&utm_campaign=Badge_Grade)
[![Codacy](https://img.shields.io/codacy/grade/3d40a551806b4c788befba6d2920675b.svg?color=black&style=flat-square)](https://www.codacy.com/manual/orhun/zps?utm_source=github.com&utm_medium=referral&utm_content=orhun/zps&utm_campaign=Badge_Grade)
[![Codecov](https://img.shields.io/codecov/c/github/orhun/zps?color=black&style=flat-square)](https://codecov.io/gh/orhun/zps)
[![Stars](https://img.shields.io/github/stars/orhun/zps.svg?color=590000&style=flat-square)](https://github.com/orhun/zps/stargazers) [![License](https://img.shields.io/github/license/orhun/zps.svg?color=590000&style=flat-square)](./LICENSE)

On Unix and Unix-like computer operating systems, a [zombie process](https://en.wikipedia.org/wiki/Zombie_process) or defunct process is a process that has completed execution (via the [exit](https://en.wikipedia.org/wiki/Exit_(system_call)) system call) but still has an entry in the process table. This occurs for child processes, where the entry is still needed to allow the parent process to read its child's exit status: once the exit status is read via the [wait](https://en.wikipedia.org/wiki/Wait_(system_call)) system call, the zombie's entry is removed from the process table and it is said to be "reaped".
On Unix and Unix-like computer operating systems, a [zombie process](https://en.wikipedia.org/wiki/Zombie_process) or defunct process is a process that has completed execution (via the [exit](<https://en.wikipedia.org/wiki/Exit_(system_call)>) system call) but still has an entry in the process table. This occurs for child processes, where the entry is still needed to allow the parent process to read its child's exit status: once the exit status is read via the [wait](<https://en.wikipedia.org/wiki/Wait_(system_call)>) system call, the zombie's entry is removed from the process table and it is said to be "reaped".

Unlike the normal processes, zombie processes cannot be removed from a system with the [kill](https://en.wikipedia.org/wiki/Kill_(command)) command since they are already dead. (This is where the term's metaphor [zombie - an undead person] comes from.) To reap a zombie process, `SIGCHLD` signal can be sent to the parent process manually using the [kill](https://en.wikipedia.org/wiki/Kill_(command)) command. If the parent process refuses to reap the zombie, then terminating the parent process (mostly with `SIGTERM` signal) can be an option. When a child process loses its parent, [init](https://en.wikipedia.org/wiki/Init) process becomes its new parent and it will reap any zombies since it executes the [wait](https://en.wikipedia.org/wiki/Wait_(system_call)) system call periodically.
Unlike the normal processes, zombie processes cannot be removed from a system with the [kill](<https://en.wikipedia.org/wiki/Kill_(command)>) command since they are already dead. (This is where the term's metaphor [zombie - an undead person] comes from.) To reap a zombie process, `SIGCHLD` signal can be sent to the parent process manually using the [kill](<https://en.wikipedia.org/wiki/Kill_(command)>) command. If the parent process refuses to reap the zombie, then terminating the parent process (mostly with `SIGTERM` signal) can be an option. When a child process loses its parent, [init](https://en.wikipedia.org/wiki/Init) process becomes its new parent and it will reap any zombies since it executes the [wait](<https://en.wikipedia.org/wiki/Wait_(system_call)>) system call periodically.

Zombie processes are not harmful since they are not affecting other processes or using any system resources. However, they do retain their [process ID](https://en.wikipedia.org/wiki/Process_identifier). This can lead to preventing new processes to launch if all the available PIDs were assigned to zombie processes. Considering Unix-like systems have a finite number of process IDs (`/proc/sys/kernel/pid_max`), it's one of the problems that zombie processes can cause. Another danger of zombie processes is that they can cause [resource leak](https://en.wikipedia.org/wiki/Resource_leak) if they stay as a zombie in the process table for a long time. Apart from these issues, having a few zombie processes won't be a big deal for the system although they might indicate a bug with their parent process.

[zproc.c](https://github.com/orhun/zps/blob/master/example/zproc.c) file can be compiled and run to see how zombie processes are created.

```
cd example/ && gcc -O3 -Wall zproc.c -o zproc && ./zproc
```

__zps__ aims to list the running processes at a particular time with stats and indicate the zombie processes on this list. It can also reap these zombie processes automatically if `--reap` argument is provided. There's also `--lreap` argument for reaping zombie processes after listing. See [usage](https://github.com/orhun/zps#usage) for more information.
Technically, __zps__ reads process stats from [/proc](https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html) filesystem and uses [C POSIX library](https://en.wikipedia.org/wiki/C_POSIX_library) to handle listing, sending signals and other operations.

- [Installation](#installation)
- [Arch Linux](#arch-linux)
- [Fedora Linux](#fedora-linux)
- [CMake](#cmake)
- [Make](#make)
- [GCC](#gcc)
- [Docker](#docker)
- [Building an image](#building-an-image)
- [Running the image in container](#running-the-image-in-container)
- [Usage](#usage)
- [zps -r](#zps--r)
- [zps -x](#zps--x)
- [zps -l](#zps--l)
- [zps -p](#zps--p)
- [TODO(s)](#todos)
- [License](#license)
- [Copyright](#copyright)
**zps** aims to list the running processes at a particular time with stats and indicate the zombie processes on this list. It can also reap these zombie processes automatically if `--reap` argument is provided. There's also `--lreap` argument for reaping zombie processes after listing. See [usage](https://github.com/orhun/zps#usage) for more information.
Technically, **zps** reads process stats from [/proc](https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html) filesystem and uses [C POSIX library](https://en.wikipedia.org/wiki/C_POSIX_library) to handle listing, sending signals and other operations.

<details>
<summary>Table of Contents</summary>

<!-- vim-markdown-toc GFM -->

- [Installation](#installation)
- [Arch Linux](#arch-linux)
- [Fedora Linux](#fedora-linux)
- [CMake](#cmake)
- [Make](#make)
- [GCC](#gcc)
- [Docker](#docker)
- [Building an image](#building-an-image)
- [Running the image in container](#running-the-image-in-container)
- [Usage](#usage)
- [zps -r](#zps--r)
- [zps -x](#zps--x)
- [zps -l](#zps--l)
- [zps -p](#zps--p)
- [TODO(s)](#todos)
- [License](#license)
- [Copyright](#copyright)

<!-- vim-markdown-toc -->

</details>

## Installation

Expand Down Expand Up @@ -130,8 +140,8 @@ Options:

## TODO(s)

* Improve listing processes for long process names.
* Send `SIGCHLD` signal to the parent instead of terminating it.
- Improve listing processes for long process names.
- Send `SIGCHLD` signal to the parent instead of terminating it.

## License

Expand Down
53 changes: 29 additions & 24 deletions README_KO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,45 @@

[![Build](https://img.shields.io/github/workflow/status/orhun/zps/Continuous%20Integration?color=black&style=flat-square)](https://github.com/orhun/zps/actions?query=workflow%3A%22Continuous+Integration%22)
[![Docker Build](https://img.shields.io/github/workflow/status/orhun/zps/Docker%20Automated%20Builds?color=black&style=flat-square&label=docker)](https://github.com/orhun/zps/actions?query=workflow%3A%22Docker+Automated+Builds%22)
[![Codacy](https://img.shields.io/codacy/grade/3d40a551806b4c788befba6d2920675b.svg?color=black&style=flat-square)](https://www.codacy.com/manual/orhun/zps?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=orhun/zps&amp;utm_campaign=Badge_Grade)
[![Codacy](https://img.shields.io/codacy/grade/3d40a551806b4c788befba6d2920675b.svg?color=black&style=flat-square)](https://www.codacy.com/manual/orhun/zps?utm_source=github.com&utm_medium=referral&utm_content=orhun/zps&utm_campaign=Badge_Grade)
[![Codecov](https://img.shields.io/codecov/c/github/orhun/zps?color=black&style=flat-square)](https://codecov.io/gh/orhun/zps)
[![Stars](https://img.shields.io/github/stars/orhun/zps.svg?color=590000&style=flat-square)](https://github.com/orhun/zps/stargazers) [![License](https://img.shields.io/github/license/orhun/zps.svg?color=590000&style=flat-square)](./LICENSE)

Unix와 컴퓨터 운영체제와 같은 Unix에서, [좀비 프로세스](https://en.wikipedia.org/wiki/Zombie_process) 또는 Defunct 프로세스는 (시스템 호출 [종료](https://en.wikipedia.org/wiki/Exit_(system_call))을 통해 이루어진) 종료가 되어도 프로세스 목록에 남아 있습니다. 이 현상은 부모 프로세스가 (시스템 호출 [중단](https://en.wikipedia.org/wiki/Wait(system_call))을 통해) 자식의 종료 상태를 알 필요가 있는 목록에서 자식 프로세스들에게 발생됩니다. 그렇게 좀비 프로세스를 목록에서 제거할 수 있었고, 이것을 "reaped"라고 합니다.
Unix와 컴퓨터 운영체제와 같은 Unix에서, [좀비 프로세스](https://en.wikipedia.org/wiki/Zombie_process) 또는 Defunct 프로세스는 (시스템 호출 [종료](<https://en.wikipedia.org/wiki/Exit_(system_call)>)을 통해 이루어진) 종료가 되어도 프로세스 목록에 남아 있습니다. 이 현상은 부모 프로세스가 (시스템 호출 [중단](<https://en.wikipedia.org/wiki/Wait(system_call)>)을 통해) 자식의 종료 상태를 알 필요가 있는 목록에서 자식 프로세스들에게 발생됩니다. 그렇게 좀비 프로세스를 목록에서 제거할 수 있었고, 이것을 "reaped"라고 합니다.

일반 프로세스들과 다르게, 좀비프로세스들은 이미 죽었기 때문에 [Kill](https://en.wikipedia.org/wiki/Kill_(command)) 명령어로 좀비프로세스들을 시스템에서 제거할 수 없습니다. (This is where the term's metaphor [zombie - an undead person] comes from.) 좀비 프로세스를 끄기 위해서, 'SIGCHLD' 신호를 부모 프로세스에게 [Kill](https://en.wikipedia.org/wiki/Kill_(command)) 명령어로 보내야 한다. 만약, 부모 프로세스가 좀비 프로세스를 끄는 것을 방해하는 경우에, 부모 프로세스는 대부분 'SIGTERM' 신호로 종료할 수 있는 방법도 있다. 자식 프로세스가 부모 프로세스를 잃었을 때, [init](https://en.wikipedia.org/wiki/Init) 프로세스(PID가 1번인 프로세스, 모든 프로세스의 조상 역할을 함.)가 자식 프로세스의 새로운 조상이 되고, 그것은 좀비 프로세스들을 시스템 호출 [중단](https://en.wikipedia.org/wiki/Wait_(system_call))을 해서 끌 수 있습니다.
일반 프로세스들과 다르게, 좀비프로세스들은 이미 죽었기 때문에 [Kill](<https://en.wikipedia.org/wiki/Kill_(command)>) 명령어로 좀비프로세스들을 시스템에서 제거할 수 없습니다. (This is where the term's metaphor [zombie - an undead person] comes from.) 좀비 프로세스를 끄기 위해서, 'SIGCHLD' 신호를 부모 프로세스에게 [Kill](<https://en.wikipedia.org/wiki/Kill_(command)>) 명령어로 보내야 한다. 만약, 부모 프로세스가 좀비 프로세스를 끄는 것을 방해하는 경우에, 부모 프로세스는 대부분 'SIGTERM' 신호로 종료할 수 있는 방법도 있다. 자식 프로세스가 부모 프로세스를 잃었을 때, [init](https://en.wikipedia.org/wiki/Init) 프로세스(PID가 1번인 프로세스, 모든 프로세스의 조상 역할을 함.)가 자식 프로세스의 새로운 조상이 되고, 그것은 좀비 프로세스들을 시스템 호출 [중단](<https://en.wikipedia.org/wiki/Wait_(system_call)>)을 해서 끌 수 있습니다.

좀비 프로세스들은 다른 프로세스들에 영향을 끼치거나 시스템 자원을 사용하지 않기 때문에 해롭지 않습니다. 하지만, 그들은 [프로세스 ID](https://en.wikipedia.org/wiki/Process_identifier)를 소유하고 있습니다. 이것은 모든 사용 가능한 PID를 좀비 프로세스가 차지하고 있다면 새로운 프로세스를 실행하는 것이 불가능 할 수 있습니다. Unix와 같은 시스템들에서는 프로세스 ID (`/proc/sys/kernel/pid_max`)를 한정된 양(제 우분투에서는 32768이 최댓값이네요.)만 갖고 있습니다. 이것만이 좀비 프로세스가 일으킬 수 있는 문제점입니다. 좀비 프로세스의 다른 위험성은 만약 좀비 프로세스가 프로세스 목록에 오랫동안 머무른다면, [메모리 누수](https://en.wikipedia.org/wiki/Resource_leak)를 일으킬 수 있다는 것입니다. 이러한 문제 외에도, 적은 양의 좀비 프로세스는 그들의 부모 프로세스에 버그를 생성할 지라도 시스템에 큰 영향을 주지는 않을 것입니다.

[zproc.c](https://github.com/orhun/zps/blob/master/example/zproc.c) 파일을 컴파일 할 수 있고, 어떻게 좀비 프로세스가 생성되는지 확인할 수 있습니다.

```
cd example/ && gcc -O3 -Wall zproc.c -o zproc && ./zproc
```

특정 시간에 실행하고 있는 프로세스들의 정보의 리스트와 좀비 프로세스들을 표시하기 위해 __zps__를 만들었습니다. 이 프로그램은 `--reap` 옵션을 사용했을 때, 자동으로 좀비 프로세스들을 끌 수 있습니다. 프로세스 리스트를 나열하기 전에 좀비 프로세스를 끄는 `--lreap` 옵션도 존재합니다. 좀 더 자세한 정보를 보려면 [사용법](https://github.com/orhun/zps#usage)을 보세요.
기술적으로, __zps__[/proc](https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html) 파일 시스템에서 프로세스 정보를 얻어오고, 프로세스를 출력하고 신호를 보내고 이외의 다른 동작들을 하기 위해 [C POSIX library](https://en.wikipedia.org/wiki/C_POSIX_library)를 이용합니다.

- [설치 방법](#설치-방법)
- [Arch Linux](#arch-linux)
- [CMake](#cmake)
- [Make](#make)
- [GCC](#gcc)
- [Docker](#docker)
- [이미지 생성](#이미지-생성)
- [컨테이너에서 이미지 실행](#컨테이너에서-이미지-실행)
- [사용법](#사용법)
- [zps -r](#zps--r)
- [zps -x](#zps--x)
- [zps -l](#zps--l)
- [zps -p](#zps--p)
- [TODO(s)](#todos)
- [License](#license)
- [Copyright](#copyright)
특정 시간에 실행하고 있는 프로세스들의 정보의 리스트와 좀비 프로세스들을 표시하기 위해 **zps**를 만들었습니다. 이 프로그램은 `--reap` 옵션을 사용했을 때, 자동으로 좀비 프로세스들을 끌 수 있습니다. 프로세스 리스트를 나열하기 전에 좀비 프로세스를 끄는 `--lreap` 옵션도 존재합니다. 좀 더 자세한 정보를 보려면 [사용법](https://github.com/orhun/zps#usage)을 보세요.
기술적으로, **zps**[/proc](https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html) 파일 시스템에서 프로세스 정보를 얻어오고, 프로세스를 출력하고 신호를 보내고 이외의 다른 동작들을 하기 위해 [C POSIX library](https://en.wikipedia.org/wiki/C_POSIX_library)를 이용합니다.

<!-- vim-markdown-toc GFM -->

- [설치 방법](#설치-방법)
- [Arch Linux](#arch-linux)
- [CMake](#cmake)
- [Make](#make)
- [GCC](#gcc)
- [Docker](#docker)
- [이미지 생성](#이미지-생성)
- [컨테이너에서 이미지 실행](#컨테이너에서-이미지-실행)
- [사용법](#사용법)
- [zps -r](#zps--r)
- [zps -x](#zps--x)
- [zps -l](#zps--l)
- [zps -p](#zps--p)
- [TODO(s)](#todos)
- [License](#license)
- [Copyright](#copyright)

<!-- vim-markdown-toc -->

## 설치 방법

Expand Down Expand Up @@ -123,8 +128,8 @@ docker run zps

## TODO(s)

* 긴 이름을 가진 프로세스를 출력하는 것을 보완하는 것.
* 종료하는 것 대신에 부모 프로세스에게 `SIGCHLD` 신호를 보내는 것.
- 긴 이름을 가진 프로세스를 출력하는 것을 보완하는 것.
- 종료하는 것 대신에 부모 프로세스에게 `SIGCHLD` 신호를 보내는 것.

## License

Expand Down

0 comments on commit 1e91a9d

Please sign in to comment.