fetch pid of new process in tmux

10 views
Skip to first unread message

kal le

unread,
Jul 15, 2020, 3:38:49 AM7/15/20
to tmux-users
Hi
I hope you are doing great! 
I'm trying to fetch the pid of a command that I execute within tmux.

So I'm in linux and starting a command like this
tmux new-window -n foo "sleep 10"

and now I want to fetch the pid of the "sleep 10" process.
The best solution I found (I can have multiple of the same process within tmux) is to
tmux list-panes -a -F "#{window_name} #{pane_pid}" | grep foo

Do you know a better way to do this?
Thanks and best wishes! /Karl

Nicholas Marriott

unread,
Jul 15, 2020, 3:41:39 AM7/15/20
to kal le, tmux-users
P=$(tmux new -dnfoo -PF '#{pane_id}' 'sleep 10')
tmux display -pt$P '#{pane_pid}'




On Wed, Jul 15, 2020 at 12:38:49AM -0700, kal le wrote:
> Hi
> I hope you are doing great!A
> IFrame
>
> --
> You received this message because you are subscribed to the Google Groups
> "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/tmux-users/bd1a5d98-72ba-4b73-a0ce-c78c17c94b30o%40googlegroups.com.

kal le

unread,
Jul 15, 2020, 4:12:17 AM7/15/20
to tmux-users
Thanks NIcholas!
That is much better since it gets the exact pane id. :)
Best wishes! /Karl

kal le

unread,
Jul 15, 2020, 4:17:20 AM7/15/20
to tmux-users
I used you arguments and got the pid directly.
tmux new -dn foo -PF '#{pane_pid}' 'sleep 10'

Best wishes! /Karl

On Wednesday, 15 July 2020 09:41:39 UTC+2, Nicholas Marriott wrote:
P=$(tmux new -dnfoo -PF '#{pane_id}' 'sleep 10')
tmux display -pt$P '#{pane_pid}'




On Wed, Jul 15, 2020 at 12:38:49AM -0700, kal le wrote:
>    Hi
>    I hope you are doing great!A
>    I'm trying to fetch the pid of a command that I execute within tmux.
>    So I'm in linux and starting a command like this
>    tmux new-window -n foo "sleep 10"
>    and now I want to fetch the pid of the "sleep 10" process.
>    The best solution I found (I can have multiple of the same process within
>    tmux) is to
>    tmux list-panes -a -F "#{window_name} #{pane_pid}"  | grep foo
>    Do you know a better way to do this?
>    Thanks and best wishes! /Karl
>    IFrame
>
>    --
>    You received this message because you are subscribed to the Google Groups
>    "tmux-users" group.
>    To unsubscribe from this group and stop receiving emails from it, send an
>    email to tmux-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages