2

I'm currently on a Debian 10 machine working as a small server. I installed aria2c and use it as a download service. Everything is working probably so far. My question is:

  • I started the aria2c as a daemon with an init.d script.
  • There will be written a pid file.
  • If I check the processes, the PID of aria2c is different than the PID in the file.

Can someone explain me why? (Please note - this is not a functional problem for me, I like to understand why. Or maybe I'm doing something wrong...)

$ cat /var/run/aria2c.pid
561
$ sudo /etc/init.d/aria2 status
...
CGroup: /system.slice/aria2.service
       └─565 /usr/bin/aria2c --daemon=true --enable-rpc --conf-path=/etc/aria2.conf
$ pgrep aria2
565
$ ps ax | grep aria*
  565 ?        Ss     0:36 /usr/bin/aria2c --daemon=true --enable-rpc --conf-path=/etc/aria2.conf
$ cat /proc/56
56/  565/ 

So this means for me that the process 561 is not existing any more. But why do I have this PID in my pid file?

Andreas
  • 21

1 Answers1

0

I disclaim any experience with the downloader daemon you refer to, but...

  1. Did you write the RC script yourself?
  2. Does aria2c stop properly when you run /etc/init.d/aria2 stop ? (i.e. not leaving lingering process around?)

If yes to (1) and no to (2), it is probably because aria2c spawned a child to do the real work, and you didn't properly suppress that in your RC script.

Many programs have a daemon mode where the program you invoke would spawn a child and daemonize:

  1. The program will fork a child process.
  2. Child process change working directory to / .
  3. Child process cut off its own standard input/output/error.
  4. Child process detache itself from current session.
  5. Parent process (which you invoked) terminate.
  6. Child process stay in the background to do the real work.

The process ID you caught in PID file is probably the parent process (that have already been terminated).

Note that the process ID from PID file is also used when you stop the daemon (/etc/init.d/aria2 stop). If it is incorrect, e.g. refer to already-terminated parent process rather than real daemon— result is the daemon won't stop; and you would have to kill it manually.

A solution would be running aria2c without --daemon parameter, to stop it from daemonizing itself (thus correct process ID could be stored in PID file), but you would have to do the daemonize part yourself in your RC script.

P.S. If you already run aria2c in your RC script via Debian's start-stop-daemon helper, then most of the task are already done for you; but you must supply --background and --chdir / options to start-stop-daemon too.