Solved

What is the pid file? where is its location and what is its use?

Posted on 2008-06-20
6
433 Views
Last Modified: 2010-04-21
What is a pid file? what is its location and where it is used ?
if i create a shell script which runs and do only sleep and its runs on background, will it create a pid file?
where will be located ?
0
Comment
Question by:jaisonshereen
  • 5
6 Comments
 
LVL 16

Expert Comment

by:Hanno Schröder
Comment Utility
A PID file will have to be created by the process (in your case your script) itself.

The purpose is to easily find the PID (Process ID) of the active process without
need to run a "ps -ef | grep <process-name>" or the like.
0
 

Author Comment

by:jaisonshereen
Comment Utility
Where will be the file? And will it be deleted when the process stops?
0
 
LVL 16

Accepted Solution

by:
Hanno Schröder earned 500 total points
Comment Utility
Usually PID files are being stored eitehr under /var/.... somewhere or (more
historically) in /etc with a name like
  programname.pid

For example, if you have a background process with the name mybgproc,
you could create a file /var/tmp/mybgproc.pid which only contains the PID
of the proc just started.

This will allow for easy stopping of mybgproc with the command
  kill -9 `cat /var/tmp/mybgproc.pid
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:Hanno Schröder
Comment Utility
Also, when the process gets stopped (or even worse: dies) you
will have to make sure it gets cleared/removed yourself.
0
 
LVL 16

Expert Comment

by:Hanno Schröder
Comment Utility
oops, typo alert --> it should read
   
kill -9 `cat /var/tmp/mybgproc.pid`

Open in new window

0
 
LVL 16

Expert Comment

by:Hanno Schröder
Comment Utility

#!/bin/sh
 

# a sample shell script to illustrate usage of PID file
 

# save this script's PID in a file

echo $$ > /var/tmp/myscript.pid
 

# make sure PID file will get removed when we get killed:

trap 'echo "I got killed!"; rm -f var/tmp/myscript.pid'  2 3
 

# this is a loop that runs forever

while : ; do sleep 60; done

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now