[SOLVED] Getting porcess id

Is there a way to get Process ID when i start app? How?
If that would be possible, i could make some wonderful things…

DestroyFunc PidFeedback
AddToFunc   PidFeedback
+ I UnsetEnv pid
+ I PipeRead `echo exec $0 && echo SetEnv pid $$$$`
+ I SomethingThatUses $[pid]
PidFeedback xcalc

– Thomas Adam

That was very fast, thanks…
Also one more question on this matter:
Is there a way to get pid of already running app?

DestroyFunc PidOfSomething
AddToFunc   PidOfSomething
+ I UnSetEnv pid$0
+ I PipeRead `echo SetEnv pid$0 $(pidof $0)`
+ I DoSomethingWith $[pid$0]
PidOfSomething somerunningapplicationname

– Thomas Adam



I’m not getting this to work correctly. I want SomethingThatUses to be a C program that takes a pid argument.
I’ve tried:

  • I Exec c_program $[pid]

  • I c_program $[pid]

  • I Exec exec c_program $[pid]

The C program always reads the environment variable and the argument as just a $

Bloody BBCode…

The PipeRead line wants five $$$$$ in it not four:

+ I PipeRead `echo exec $0 && echo SetEnv pid $$$$$`

(Hopefully that line above renders OK.)

– Thomas Adam

Thanks, now my C program is getting the pid. However, I noticed the following behavior.

I applied the PidFeedback function to xterm. When the C program is called it has the process id not of the xterm, but likely the PipeRead process? For example, I launch xterm and a ps shows the new xterm has a process id of 5851, but the C program is getting 5850. The xterm has a ppid of 5037, which is fvwm’s process id.


That is to be expected the way it is written above. To get around that you need to do some trick to start a background process from within the PipeRead, and get the pid of that process, and then exec the xterm from it.

This can be done using a wrapper script. (it might be possible without also)

echo $$
exec "$@" 1>&-

(Note that it is important to close stdout on the exec, or PipeRead won’t return)

and then change the PipeRead to

PipeRead "echo SetEnv pid `(pid_wrapper $*)&`"