?
Solved

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

Posted on 2008-06-20
6
Medium Priority
?
459 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 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