Why Does Android's 'su' Kill Child Processes?
in Post with 0 comment

I recently encountered a strange issue with Tar on Android using Magisk su. The compress child process was abruptly killed once the archiver process completed. This behavior differs from the expected behavior of 'su' on Linux.

Here's a breakdown of what I observed:

**Reproduction Steps on Android with Magisk su:**

1. Execute: `su root -c "sleep 123 &"`
2. List running processes: `ps -A | grep sleep`
3. You'll likely see no results.

**Expected Behavior:**

The `sleep` process should remain running in the background.

**Observations:**

- **Android 'su'**: The child (`sleep`) process gets terminated immediately after the parent (`archiver`) process finishes.
- **Standard 'su' (Debian):** The child (`sleep`) process continues to run as expected.

**Code Examples:**

* **Android:**
```
su root -c "sleep 123 &"
ps -A | grep sleep
# No sleep process found
```

* **Debian:**
```
/system/bin/sh -c "sleep 123 &"
ps -A | grep sleep
root 30923 1 11560 3620 __se_sys_nanosleep_time32 0 S sleep
```

**Questions:**

- Is the termination of child processes by Android's 'su' a deliberate design choice?
- If so, what are the reasons behind it?
- Is there a way to override or disable this behavior?

**Device Information:**

- Android Emulator
- Android Version: 11
- Magisk Version Code: 28.1

The article has been posted for too long and comments have been automatically closed.