Solved

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

Posted on 2008-06-20
6
448 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 500 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

691 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