6

I have a managed VPS running on CloudLinux 6.6 x86_64 standard.

It has a few websites with MySQL, PHP and Apache running with CPanel.

I am working on a PHP system that needs to manage a PID and detect it's status.

I have defined an smallint field (2 bytes) on my MySQL database to store the PID.

But today, I noticed something weird:

The service was "acting up" and saying that the process wasn't running when in fact the task finished.

I looked it up and there were processes with PID's as high as 997282 (highest so far).

I tried to look this over on Google and nothing that helps me.

I only found informations about the file /proc/sys/kernel/pid_max which I used to read it and get the maximum PID from there, which is 1048576.

Is this normal to have PID's over 65535?

Kind of unrelated: Is the server screaming for a reboot when the PID's get above 10000?

Any additional information you might need, I am willing to provide to a certain point where no secret is revealed.

Ismael Miguel
  • 173
  • 1
  • 10

2 Answers2

7

PIDs are recycled. When a process exits its PID can be used later by another process, so you don't "run out" or need to reboot simply because a PID near the maximum value exists But see below...

I don't modify this sysctl parameter unless it's necessary; e.g. working on a busy system withe lots of short-lived processes or a heavily multithreaded application with long-running processes.

Usually I set to 99999 or in some cases, 999999...

In one notable case, I had a database server that ran out of process IDs. PIDs were being exhausted by an average of 9,000-10,000 concurrent database connections. Each spawned several threads, hitting the 32,768 limit configured in the OS. This raised the system load average because of the high run queue.

Raising the PID maximum value relieved the pressure.

Edit:

If this is a VPS, I think the host would have a high pid_max value because the PIDs are shared amongst the guests on the system. It's probably to provide headroom.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
ewwhite
  • 197,159
  • 92
  • 443
  • 809
  • I just wanted to know if it was normal for PID's to go this high. The server barely has any accesses. That's why I asked this. And I can't raise them: I don't have permissions. – Ismael Miguel Nov 28 '14 at 15:37
  • It's not normal, but there are reasons that a server may be configured for higher PIDs. This also may depend on your Linux distribution, as they can ship with different default settings. – ewwhite Nov 28 '14 at 15:38
  • Maybe they were predicting that something similar that happened to you would happen to us. I am using `ps` to check the PID's and the highest now is `1015869`. – Ismael Miguel Nov 28 '14 at 15:40
  • See my edit above. – ewwhite Nov 28 '14 at 15:42
  • Your edit makes sense, but I'm not confortable with `ps` telling me that the highest PID is `1018964`. That's 3095 in 2 minutes. – Ismael Miguel Nov 28 '14 at 15:43
  • @IsmaelMiguel There are other VMs on the host, right? They have their own PIDs. You can't see them... – ewwhite Nov 28 '14 at 15:52
  • That sounds like a good reason. Thank you for answering my question and for your time. I still will check it with the provider. I don't like this behavior, even though it might be normal. – Ismael Miguel Nov 28 '14 at 16:15
  • I still have to decide on which one. Both answers are great ones. I'm having an hard time to decide. – Ismael Miguel Nov 28 '14 at 20:31
6

The theoretical maximum pid number of 32 bit systems is 32768 and for 64 bit systems 4194304. You can define another cap that is below this numbers in the file you mentioned in your question (/proc/sys/kernel/pid_max).

If the pid_max is reached (by running processes) the system doesn't allow new processes to be created until existing ones exit and get cleaned up. So you have no problem unless your system has 1048576 running processes.

chaos
  • 1,505
  • 1
  • 15
  • 21
  • It doesn't have that many, but it is at `1014873` by now. Isn't it a little high since you answered 9 minutes ago? – Ismael Miguel Nov 28 '14 at 15:38
  • @IsmaelMiguel seems that your system creates many new processes. You should find out why. But, the pid maximum should not be a problem – chaos Nov 28 '14 at 15:43
  • I really don't like this, but I can't do much. It is managed and I have barely any permissions to do anything. We have luck to have SSH! – Ismael Miguel Nov 28 '14 at 15:48
  • 1
    @IsmaelMiguel true, since its a VPS with other users on it, maybe they generate those processes. Maybe you can call your provider, that they move your instance to another machine that is less busy... – chaos Nov 28 '14 at 15:53
  • The last time they moved the VPS, they ruined everything! They didn't told us that they changed the server and made some bad changes: the MySQL port was changed silently, the emails stopped working and we had to re-configure over 20 accounts on our clients, some DNS records were messed up and many inconsistencies. I don't want that again – Ismael Miguel Nov 28 '14 at 15:56
  • @IsmaelMiguel Then you have 2 options: 1. live with it or 2. change the provider – chaos Nov 28 '14 at 15:57
  • Changing provider sounds a better idea. But I can't do it in the near future. For now, I will live with it and swallow this one. Thank you for your help and time. – Ismael Miguel Nov 28 '14 at 16:09