executing gvim from within a C program

27 views
Skip to first unread message

Lucien Gentis

unread,
May 13, 2020, 4:28:26 PM5/13/20
to v...@vim.org

Hello,

Distro : Debian 10 - 64bits

I think it's the right list ; if not, please redirect me.

In order to launch a command from within the C programme in attachment, I use "fork - execve - wait" trio so that parent program waits until command has finished

Building the program : cc execve.c -o execve

Program syntax : ./execve <command full path>

Example : ./execve /usr/bin/gvim

The problem :

--- if I execute "./execve /usr/bin/gvim", gvim starts after a few seconds but without executing .vimrc, and parent program doesn't wait for gvim to end.

Output of "ps -auwx --forest" during the few wait seconds :

lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss   14:47      0:00  \_ bash
lgentis   9368  0.0  0.0   2144   752 pts/0    S+   16:44      0:00  |   \_ ./execve /usr/bin/gvim
lgentis   9369  2.0  0.2  68916 16452 pts/0    S+   16:44   0:00  |       \_ gvim
lgentis   9392  2.5  0.3  71620 22444 ?        Ss   16:44      0:00  |           \_ gvim

Output of "ps -auwx --forest" once gvim started :

lgentis   5212  0.1  0.7 426212 43880 ?        Rl   14:47    0:07 xfce4-terminal
lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss+  14:47   0:00  \_ bash
lgentis   9093  1.3  0.4  75804 26700 ?        Ss   16:36     0:00 gvim

We can see that  gvim is not a child process of the parent program (which has ended)

--- if I execute "./execve /usr/bin/vim.gtk", vim starts in text mode in the console ; however, parent program waits till vim is closed.

Output of "ps -auwx --forest"  :

lgentis   5212  0.0  0.7 426212 43880 ?        Rl   14:47      0:06 xfce4-terminal
lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss   14:47      0:00  \_ bash
lgentis   9011  0.0  0.0   2144   748 pts/0    S+   16:34      0:00  |   \_ ./execve /usr/bin/vim.gtk
lgentis   9012  0.8  0.2  68932 17232 pts/0    S+   16:34   0:00  |       \_ vim.gtk

 We can see that  vim.gtk is a child process of the parent program

--- I did the same test with gedit and audacious, and all works fine :  child program is executed and parent program waits as expected.

Output of "ps -auwx --forest" :

lgentis   5212  0.0  0.7 425664 43548 ?        Sl   14:47       0:05 xfce4-terminal
lgentis   5216  0.0  0.0   7124  3812 pts/0    Ss   14:47       0:00  \_ bash
lgentis   8910  0.0  0.0   2144   748 pts/0    S+   16:30       0:00  |   \_ ./execve /usr/bin/gedit
lgentis   8911  4.2  0.7 477720 47812 pts/0    Sl+  16:30   0:00  |       \_ gedit

We can see that  gedit is a child process of the parent program

execve.c

Tony Mechelynck

unread,
May 13, 2020, 4:34:18 PM5/13/20
to vim_use, Vim mailing list
On Wed, May 13, 2020 at 10:28 PM Lucien Gentis <lucien...@waika9.com> wrote:
>
> Hello,
>
> Distro : Debian 10 - 64bits
>
> I think it's the right list ; if not, please redirect me.

It is.
>
> In order to launch a command from within the C programme in attachment, I use "fork - execve - wait" trio so that parent program waits until command has finished
>
> Building the program : cc execve.c -o execve
>
> Program syntax : ./execve <command full path>
>
> Example : ./execve /usr/bin/gvim
>
> The problem :
>
> --- if I execute "./execve /usr/bin/gvim", gvim starts after a few seconds but without executing .vimrc, and parent program doesn't wait for gvim to end.
>
> Output of "ps -auwx --forest" during the few wait seconds :
>
> lgentis 5216 0.0 0.0 7124 3812 pts/0 Ss 14:47 0:00 \_ bash
> lgentis 9368 0.0 0.0 2144 752 pts/0 S+ 16:44 0:00 | \_ ./execve /usr/bin/gvim
> lgentis 9369 2.0 0.2 68916 16452 pts/0 S+ 16:44 0:00 | \_ gvim
> lgentis 9392 2.5 0.3 71620 22444 ? Ss 16:44 0:00 | \_ gvim
>
> Output of "ps -auwx --forest" once gvim started :
>
> lgentis 5212 0.1 0.7 426212 43880 ? Rl 14:47 0:07 xfce4-terminal
> lgentis 5216 0.0 0.0 7124 3812 pts/0 Ss+ 14:47 0:00 \_ bash
> lgentis 9093 1.3 0.4 75804 26700 ? Ss 16:36 0:00 gvim
>
> We can see that gvim is not a child process of the parent program (which has ended)

see :help -f

>
> --- if I execute "./execve /usr/bin/vim.gtk", vim starts in text mode in the console ; however, parent program waits till vim is closed.
>
> Output of "ps -auwx --forest" :
>
> lgentis 5212 0.0 0.7 426212 43880 ? Rl 14:47 0:06 xfce4-terminal
> lgentis 5216 0.0 0.0 7124 3812 pts/0 Ss 14:47 0:00 \_ bash
> lgentis 9011 0.0 0.0 2144 748 pts/0 S+ 16:34 0:00 | \_ ./execve /usr/bin/vim.gtk
> lgentis 9012 0.8 0.2 68932 17232 pts/0 S+ 16:34 0:00 | \_ vim.gtk
>
> We can see that vim.gtk is a child process of the parent program
>
> --- I did the same test with gedit and audacious, and all works fine : child program is executed and parent program waits as expected.
>
> Output of "ps -auwx --forest" :
>
> lgentis 5212 0.0 0.7 425664 43548 ? Sl 14:47 0:05 xfce4-terminal
> lgentis 5216 0.0 0.0 7124 3812 pts/0 Ss 14:47 0:00 \_ bash
> lgentis 8910 0.0 0.0 2144 748 pts/0 S+ 16:30 0:00 | \_ ./execve /usr/bin/gedit
> lgentis 8911 4.2 0.7 477720 47812 pts/0 Sl+ 16:30 0:00 | \_ gedit
>
> We can see that gedit is a child process of the parent program



Best regards,
Tony.

Lucien Gentis

unread,
May 14, 2020, 1:55:20 PM5/14/20
to vim...@googlegroups.com
Thanks a lot, Tony ; that was the solution ; yet gvim is launched (after
6 seconds ???), and parent program waits till gvim is closed.

Just a little thing : this child instance of gvim does not read my
.vimrc unless I ad "-u /myHome/.vimrc"

And if I add "-u /myHome/.vimrc" and do "Edition - startup setting", it
says "new file .vimrc"

Reply all
Reply to author
Forward
0 new messages