LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 03:56 PM   #1
tonj
Member
 
Registered: Sep 2008
Posts: 514

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, 06:54 PM   #2
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 517
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, 08:19 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,285

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

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 06:56 AM.
 
Old 05-09-2014, 10:06 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,866

Rep: Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487
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, 04:36 PM   #6
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 997

Rep: Reputation: 130Reputation: 130
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 01:12 AM
[SOLVED] how to read a PID from a text file and kill the corresponding process sneakyimp Linux - Newbie 3 06-30-2010 02:52 PM
sshd not creating PID file [CentOS5] neocookie Linux - Server 4 12-17-2008 08:36 AM
manager of PID file quit without update while starting mysqld abyabahai LinuxQuestions.org Member Intro 0 11-20-2008 12:54 AM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 03:37 PM

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

All times are GMT -5. The time now is 04:32 PM.

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