Questions tagged [pidfile]

A pidfile is a file containing the process ID of a running program.

A pidfile is a file containing the process ID of a running program (usually a daemon). The pidfile is useful to check that the daemon is still running or to send it a signal (for example to kill it).

Pidfiles can be written either by the daemon itself or by the monitoring program that launches it. The latter option is preferable because the daemon could die suddenly (e.g. due to a SIGKILL) and its pidfile would remain while its process ID could be reused by a new process.

26 questions
103
votes
3 answers

What are pid and lock files for?

I often see that programs specify pid and lock files. And I'm not quite sure what they do. For example, when compiling nginx: --pid-path=/var/run/nginx.pid \ --lock-path=/var/lock/nginx.lock \ Can somebody shed some light on this one?
Stann
  • 2,159
  • 5
  • 23
  • 24
4
votes
1 answer

start-stop-daemon makes cron pidfile with wrong pid

I have an init.d script to start crond which specifies the following for start(): start-stop-daemon -S --quiet --make-pidfile --pidfile /var/run/crond.pid --background --exec /usr/sbin/crond However, the PID is always one number higher than what's…
trycatch
  • 623
  • 2
  • 8
  • 15
3
votes
1 answer

How to check if process with pid X is the one you expect

In our application, we start some background processes. The pid of these processes is saved to a file. pids values are re-used when the maximum is reached or when the system is rebooted. How can I reliably check that the process with pid X is still…
carl verbiest
  • 471
  • 4
  • 11
3
votes
6 answers

Fastest way of finding files which contain exclusively some text

I'm trying to figure out the best and fastest way of finding files whose content is specifically "something" Here's the reason: I have a process that I'm pretty sure stores its PID somewhere in a file, but I don't know where (and I want to find…
Savir
  • 1,221
  • 1
  • 17
  • 24
3
votes
1 answer

Check and Test Lock from other Process

I am trying to create a service wrapper (init.d script) around one of my favorite applications. The application creates both a PID and a lock file, and so I'm trying to use those to ensure that I can report accurate status of the application and…
palswim
  • 4,919
  • 6
  • 37
  • 53
3
votes
2 answers

How to detect out-bound port from PID

I have several applications that run on random ports. How would I take the pid or the file location and find which port it is running on? Example of desired output: www-data/apache = 80 my-awesome-game = 2023
Joe John
  • 31
  • 1
3
votes
2 answers

Writing own daemon. systemd error: Failed to read PID from file: Invalid argument

I'm trying to write own daemon a la very simple MPD (it's operating systems laboratory work). I made it work: it starts like a daemon (output of ps): 1 14877 14877 14877 ? -1 Ss 0 0:00 lab1_daemon it plays, it gets signals. The…
rominf
  • 517
  • 5
  • 16
2
votes
0 answers

CentOS 7 systemd service file (run python script) working, but logging errors?

I have an application written in python which I've used many times with CentOS 6, and am now setting it up on CentOS 7. I've created a systemd service file that contains the following: # # Systemd unit file for…
tycoonbob
  • 21
  • 1
  • 1
  • 2
2
votes
1 answer

Process id of a command ran by an user

Consider i am running just some basic command.. ls Now would the above command have a pid, when it was getting executed? If yes, then how can i determine that pid? when i try echo $! right after the ls command, it returns empty output. whereas…
Gokul
  • 1,061
  • 5
  • 16
  • 31
2
votes
1 answer

bind's path to 'named.pid' looks a bit weird after a not-so-smooth package installation

I had a fresh VPS hosting account running Ubuntu LTS (Lucid Lynx) with Plesk 10.2.0 (and etckeeper package) I used Plesk's web interface to install Plesk Health Monitor. It took two attempts because the first time it was aborted half way through.…
JW01
  • 541
  • 1
  • 6
  • 17
2
votes
4 answers

Write program output to log file containing PID in its name

How can I start a program and write its output to a log file, where the log file contains the PID in its name? I tried program_a > log_$! which doesn't work since $! is the PID of the last program and `program_a' has not finished when the log…
greole
  • 239
  • 1
  • 4
  • 10
1
vote
1 answer

Startscript: using $! to create pidfile - returning wrong pid (off by one) occasionally

We have 3 instances of redis running on a test server. For some reason, our start script which starts redis can write the wrong pid to a file. Here is what it's doing: su redis -c "redis-server /redis.conf & echo \$! > /var/run/redis_6379" If I…
JasonG
  • 395
  • 3
  • 9
1
vote
1 answer

How to demonstrate invalid PID assumptions?

It seems many programmers are happy with saving a PID to a file, and then later read and use the PID as if it was guaranteed to be the same process. It seems the general idea is that the odds are good enough to ignore. How can I simply demonstrate…
l0b0
  • 50,672
  • 41
  • 197
  • 360
0
votes
1 answer

What exactly does it mean to run a process in the "background"?

I want to understand a little bit better, what a background process is. The question came to live as a result of reading this line of code: /usr/sbin/rsyslogd -niNONE & Source The documentations says: -i pid file Specify an alternative…
Andrew Savinykh
  • 409
  • 1
  • 5
  • 12
0
votes
1 answer

remove on stale pid file after power failure to allow software startup via systemd service

i got such situation there is a power failure the UPS battery is drained during power failure the servers in rack are shut off from power lose power is restored servers powering up and their os'es are booting systemd is doing its work and now some…
ceph3us
  • 557
  • 2
  • 8
  • 22
1
2