Solved

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

Posted on 2008-06-20
6
442 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ubuntu Apache Webserver - File Permissions 5 77
Internal CA server 6 94
Shell Script- gzip 5 50
Shrink Linux Swap File Size CentOS 10 31
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

730 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