LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-06-2014, 02:56 PM   #1
tonj
Member
 
Registered: Sep 2008
Posts: 546

Rep: Reputation: 37
auto-creating a pid file when starting a process


I'm running ffmpeg-2.1.4-1 on a fedora 20 web server
I start ffmpeg by running a single (long) command in the console and I usually either put a '&' on the end to background it or I run it in a screen and then detach. It's not started by /etc/init.d/blah-de-blah. Is there a way to make ffmpeg create a pid file when it's started? ie: /var/run/ffmpeg.pid or similar.
I see from digging around that ffmpeg creates a pid but it's a number which changes every time ffmpeg is started.
To create a pid file do I need to modify the ffmpeg command? or does it have to be done by a script? I have seen a few script examples on google but they all refer to the /etc/init.d/program start method and don't fit a single command scenario. Thanks for any help.
 
Old 05-06-2014, 05:54 PM   #2
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 518
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
you can use "pidof " to find the pid of any running program. So you can do "ffmpeg <some options> & pidof ffmpeg > /tmp/ffmpeg.pid"
 
Old 05-06-2014, 07:19 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Mint, MX, antiX, SystemRescue
Posts: 2,337

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Code:
nohup sleep 30 & echo $! > pidfile
Substitute your ffmpeg command for "sleep 30" in the example above.
 
Old 05-07-2014, 05:02 AM   #4
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
@DJ: thankyou for your advice DJ, your suggestion worked, ffmpeg is now creating a pid file.

Last edited by tonj; 05-07-2014 at 05:56 AM.
 
Old 05-09-2014, 09:06 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Note: the pidof can list multiple process numbers if there are multiple instances of the application running. It does not indicate WHICH one is the one you just started.

Only the solution in post #3 will do that, as only the shell knows what the pid was of the process it just started.
 
Old 05-09-2014, 03:36 PM   #6
Pearlseattle
Senior Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 1,001

Rep: Reputation: 142Reputation: 142
Please set this thread as solved - thx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Empty PID file while starting script kapila_sr Linux - Server 3 08-17-2010 12:12 AM
[SOLVED] how to read a PID from a text file and kill the corresponding process sneakyimp Linux - Newbie 3 06-30-2010 01:52 PM
sshd not creating PID file [CentOS5] neocookie Linux - Server 4 12-17-2008 07:36 AM
manager of PID file quit without update while starting mysqld abyabahai LinuxQuestions.org Member Intro 0 11-19-2008 11:54 PM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 02:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration