?
Solved

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

Posted on 2008-06-20
6
Medium Priority
?
470 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 P.S.
ID: 21830987
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
ID: 21831004
Where will be the file? And will it be deleted when the process stops?
0
 
LVL 16

Accepted Solution

by:
Hanno P.S. earned 2000 total points
ID: 21831018
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 21831028
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 P.S.
ID: 21831039
oops, typo alert --> it should read
   
kill -9 `cat /var/tmp/mybgproc.pid`

Open in new window

0
 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 21831101

#!/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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 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