You are not logged in.

#1 2009-08-05 22:45:14

jdiez
Member
Registered: 2009-08-03
Posts: 40

Find "my own pid" [SOLVED]

Hi, I'm writing a bash script to use with a DSLR camera as a remote control.

One of the modes I thought of was something like "shoot every X seconds for Y minutes". So at first I thought of doing simple maths to calculate the number of times the script would run. But then I remembered long exposures. If you have set your camera up for firing 5 seconds, then the camera remote would have to wait 5 additional seconds and so it wouldn't be running for the specified minutes.

Then I came up with something like "getting own pid". I mean, before the loop I'll have something like:

(sleep $1 ; kill -9 $PID) &

And then run the loop normally, firing the camera.

By the way, it would also be great to get the pid of another process. Everytime the script fires a shot, it opens 'feh' for previewing, so I'd also like to be able to get this pid.

Thanks in advance!
PS: Sorry for my bad english, I'm spanish ^^'

Last edited by jdiez (2009-08-06 16:07:05)

Offline

#2 2009-08-05 22:57:43

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Find "my own pid" [SOLVED]

Try the pidof command seems like what you want.

eg:

 [mark@markspc ~]$ pidof firefox
1205
[mark@markspc ~]$

Last edited by markp1989 (2009-08-05 22:58:27)


Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

#3 2009-08-05 23:00:54

jdiez
Member
Registered: 2009-08-03
Posts: 40

Re: Find "my own pid" [SOLVED]

Thanks, markp1989!

Would that work if I called it with something like PID = `pidof feh --scale /photos/jpeg/$1.jpg` ?

Offline

#4 2009-08-05 23:01:23

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Find "my own pid" [SOLVED]

jdiez wrote:

Then I came up with something like "getting own pid".

echo $$

Offline

#5 2009-08-05 23:07:59

jdiez
Member
Registered: 2009-08-03
Posts: 40

Re: Find "my own pid" [SOLVED]

Thanks fukawi! That worked perfectly.

Offline

#6 2009-08-06 00:30:36

jdiez
Member
Registered: 2009-08-03
Posts: 40

Re: Find "my own pid" [SOLVED]

But I still don't know how to find the pid for a feh run with some settings, like

feh --scale whatever.png

Offline

#7 2009-08-06 02:12:38

majiq
Member
Registered: 2009-03-06
Posts: 259

Re: Find "my own pid" [SOLVED]

jdiez wrote:

But I still don't know how to find the pid for a feh run with some settings, like

feh --scale whatever.png
pgrep -f "feh --scale whatever.png"

Offline

#8 2009-08-06 02:13:25

jdiez
Member
Registered: 2009-08-03
Posts: 40

Re: Find "my own pid" [SOLVED]

thanks so much! that just did it!

Offline

Board footer

Powered by FluxBB