[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNUNET_OS_start_process and process arguments

From: Christian Grothoff
Subject: Re: GNUNET_OS_start_process and process arguments
Date: Sun, 13 Dec 2020 17:13:34 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0

exec also allows you to pass a filename and a different argv[0].

This can be used to give the process a different 'name' at runtime than
the binary that is actually executed. For example,

execl("/bin/cat", "mouse", "input", NULL);

will start 'cat', but argv[0] will be "mouse".

The GNUnet API to launch processes simply does support this, even if it
is rarely used.


On 12/13/20 5:10 PM, Martin Schanzenbach wrote:
> I do not understand why it is intentional.
> I also do not understand what exec has to do with it.
> exec does not behave like that:
> $ exec ./a.out hello w
> [./a.out] [hello] [w]
> BR
> On Sun, 2020-12-13 at 16:54 +0100, Christian Grothoff wrote:
>> That's intentional. Same as with 'exec'. First argument is the file
>> name/path to the binary, and argv[0] is separate. See 'exec'. In
>> general, simply pass the binary name twice.
>> -Christian
>> On 12/13/20 4:32 PM, Alessio Vanni wrote:
>>> Hello,
>>> I noticed a curious situation, best explained by this example:
>>> Let's say I have a program (let's call it 'gnunet-exec') that
>>> starts a
>>> process using `GNUNET_OS_start_process', with the program file name
>>> taken from the command line and using the two strings "hello" and
>>> "world" as arguments to the process.
>>> Let's also say I have this small program:
>>> int main(int argc, char *argv[]) {
>>>     printf("[%s] [%s] [%s]\n", argv[0], argv[1], argv[2]);
>>>     return 0;
>>> }
>>> I then get this result ($ is the shell prompt):
>>> $ ./small-program hello world
>>> [small-program] [hello] [world]
>>> $ gnunet-exec small-program
>>> [hello] [world] [(null)]
>>> Essentially, argv[0] becomes the first argument instead of
>>> containing
>>> the program name.
>>> Is this intentional or is it a bug?
>>> Thanks,
>>> A.V.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]