How to find which systemd unit owns a process

I was refering the the systemctl man page checking on systemctl status when I saw this:

status [PATTERN...|PID...]]

That’s right, you can use systemctl status <PID> and it will give you information about that process if it was started by systemd, what unit started it along with status information of that unit.

Here’s the example output for a process on this server:

# systemctl status 6555
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-12-18 11:06:57 UTC; 4h 23min ago
     Docs: man:nginx(8)
  Process: 6549 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SU
  Process: 6552 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 6553 (nginx)
    Tasks: 2 (limit: 1149)
   Memory: 22.3M
   CGroup: /system.slice/nginx.service
           ├─6553 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─6555 nginx: worker process

Dec 18 11:06:57 web-1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 18 11:06:57 web-1 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argume
Dec 18 11:06:57 web-1 systemd[1]: Started A high performance web server and a reverse proxy server.

This tells you that the process was loaded from nginx.service along with a bunch more status information on nginx.service.