Max Size of argv[1] ???

Discussion in 'C Programming' started by James, Sep 1, 2004.

  1. James

    James Guest

    consider :
    int main (int argc, char * argv [ ]) {

    }

    In exec (2) ; Whose arguments which are passed to main.

    What is the maximum size of the string.
    argv[1] = "hello........." ;

    How long can argv[1] point to. even though i know argv is 4 bytes
    pointer. How long can the string be ?.

    I just want to send a 50K string as my process arguments (main's
    args)
    when i fork and exec.

    Is it possible ?. Does standard say something on this ?.

    Are there any limitations ?.


    Regards,
    James
    James, Sep 1, 2004
    #1
    1. Advertising

  2. James

    -berlin.de Guest

    James <> wrote:
    > consider :
    > int main (int argc, char * argv [ ]) {


    > }


    > In exec (2) ; Whose arguments which are passed to main.


    > What is the maximum size of the string.
    > argv[1] = "hello........." ;


    > How long can argv[1] point to. even though i know argv is 4 bytes
    > pointer. How long can the string be ?.


    > I just want to send a 50K string as my process arguments (main's
    > args)
    > when i fork and exec.


    > Is it possible ?. Does standard say something on this ?.


    > Are there any limitations ?.


    As far as I can tell, there's no requirement for the size of it in
    the C standard (and I can't see any good reason why the standard
    should require an upper limit). On the other hand, the operating
    system will probably put a limit on the maximum size. E.g. the
    POSIX standard SUSv3 requires that argv can use at least 4096 bytes
    (but many Unices allow a lot more).

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
    -berlin.de, Sep 1, 2004
    #2
    1. Advertising

  3. Use a temp file and send the filename.
    Remember both side should close the file since the File handle is reference
    counted

    "James" <> ???
    news: ???...
    > consider :
    > int main (int argc, char * argv [ ]) {
    >
    > }
    >
    > In exec (2) ; Whose arguments which are passed to main.
    >
    > What is the maximum size of the string.
    > argv[1] = "hello........." ;
    >
    > How long can argv[1] point to. even though i know argv is 4 bytes
    > pointer. How long can the string be ?.
    >
    > I just want to send a 50K string as my process arguments (main's
    > args)
    > when i fork and exec.
    >
    > Is it possible ?. Does standard say something on this ?.
    >
    > Are there any limitations ?.
    >
    >
    > Regards,
    > James



    --
    ~ Samba, more than a low cost File and Printer server ~

    -- Let us OpenSource --


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
    Andrew Au \(Newsgroup\), Sep 1, 2004
    #3
  4. -berlin.de wrote in message news:<>...
    > James <> wrote:
    > > consider :
    > > int main (int argc, char * argv [ ]) {

    >
    > > }

    >
    > > In exec (2) ; Whose arguments which are passed to main.

    >
    > > What is the maximum size of the string.
    > > argv[1] = "hello........." ;

    >
    > > How long can argv[1] point to. even though i know argv is 4 bytes
    > > pointer. How long can the string be ?.

    >
    > > I just want to send a 50K string as my process arguments (main's
    > > args)
    > > when i fork and exec.

    >
    > > Is it possible ?. Does standard say something on this ?.

    >
    > > Are there any limitations ?.

    >
    > As far as I can tell, there's no requirement for the size of it in
    > the C standard (and I can't see any good reason why the standard
    > should require an upper limit). On the other hand, the operating
    > system will probably put a limit on the maximum size. E.g. the
    > POSIX standard SUSv3 requires that argv can use at least 4096 bytes
    > (but many Unices allow a lot more).
    >
    > Regards, Jens


    There isn't a limit on the length of an individual argument, only on
    the length of the entire argument line has the ARG_MAX limit imposed
    on it, defined in limits.h. The following makes an interesting
    comparison on the size of ARG_MAX across various systems:

    http://rhols66.adsl.netsonic.fi/era/unix/arg-max.html

    Regards,
    Mark.
    Mark R.Bannister, Sep 1, 2004
    #4
  5. James

    Joe Wright Guest

    James wrote:

    > consider :
    > int main (int argc, char * argv [ ]) {
    >
    > }
    >
    > In exec (2) ; Whose arguments which are passed to main.
    >
    > What is the maximum size of the string.
    > argv[1] = "hello........." ;
    >
    > How long can argv[1] point to. even though i know argv is 4 bytes
    > pointer. How long can the string be ?.
    >
    > I just want to send a 50K string as my process arguments (main's
    > args)
    > when i fork and exec.
    >
    > Is it possible ?. Does standard say something on this ?.
    >
    > Are there any limitations ?.
    >
    >


    How exactly would you present a 50K argument to your program? The
    concept is a little bizarre. The things normally passed through the
    char *argv[] construct are filenames and options. Data to be
    processed by the program is usually marshalled into files or other
    streams which the program gets through the i/o system.

    Better put the 50K in a file and pass the file's name to your
    program or pass the contents of the file to your program through a
    pipe to stdin.

    --
    Joe Wright mailto:
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Sep 2, 2004
    #5
  6. In article <>,
    Joe Wright <> wrote:
    ....
    >How exactly would you present a 50K argument to your program? The
    >concept is a little bizarre. The things normally passed through the
    >char *argv[] construct are filenames and options. Data to be
    >processed by the program is usually marshalled into files or other
    >streams which the program gets through the i/o system.


    The short answer is: ls *

    The longer answer is that my understanding is that on Unix/POSIX at any
    rate, the limit is (in standard C [main()]) terms: argv+envp. I.e., the
    size of the environment is often limited and the actual limit is the sum of
    the two things (these are the two things that must be cached up somewhere
    in the kernel to implement exec()).
    Kenny McCormack, Sep 2, 2004
    #6
  7. In article <ch5p44$c1l$>,
    Kenny McCormack <> wrote:

    >>How exactly would you present a 50K argument to your program?


    >The short answer is: ls *


    That presents lots of smallish arguments, which isn't exactly what the OP
    was asking about. I think a single 50k argument would be very unusual.

    -- Richard
    Richard Tobin, Sep 2, 2004
    #7
  8. In article <ch5q1m$26qd$>,
    Richard Tobin <> wrote:
    >In article <ch5p44$c1l$>,
    >Kenny McCormack <> wrote:
    >
    >>>How exactly would you present a 50K argument to your program?

    >
    >>The short answer is: ls *

    >
    >That presents lots of smallish arguments, which isn't exactly what the OP
    >was asking about. I think a single 50k argument would be very unusual.
    >
    >-- Richard


    Um, it is the total size (the sum of all the args lengths) that matters.
    Kenny McCormack, Sep 2, 2004
    #8
  9. James

    Jack Klein Guest

    On 1 Sep 2004 09:02:41 -0700, (Mark R.Bannister)
    wrote in comp.lang.c:

    > -berlin.de wrote in message news:<>...
    > > James <> wrote:
    > > > consider :
    > > > int main (int argc, char * argv [ ]) {

    > >
    > > > }

    > >
    > > > In exec (2) ; Whose arguments which are passed to main.

    > >
    > > > What is the maximum size of the string.
    > > > argv[1] = "hello........." ;

    > >
    > > > How long can argv[1] point to. even though i know argv is 4 bytes
    > > > pointer. How long can the string be ?.

    > >
    > > > I just want to send a 50K string as my process arguments (main's
    > > > args)
    > > > when i fork and exec.

    > >
    > > > Is it possible ?. Does standard say something on this ?.

    > >
    > > > Are there any limitations ?.

    > >
    > > As far as I can tell, there's no requirement for the size of it in
    > > the C standard (and I can't see any good reason why the standard
    > > should require an upper limit). On the other hand, the operating
    > > system will probably put a limit on the maximum size. E.g. the
    > > POSIX standard SUSv3 requires that argv can use at least 4096 bytes
    > > (but many Unices allow a lot more).
    > >
    > > Regards, Jens

    >
    > There isn't a limit on the length of an individual argument, only on
    > the length of the entire argument line has the ARG_MAX limit imposed
    > on it, defined in limits.h. The following makes an interesting
    > comparison on the size of ARG_MAX across various systems:


    Perhaps you thought you were responding in comp.unix.programmer, and
    not comp.lang.c. According to the C standard, a conforming compiler
    is not allowed to define a macro in <limits.h>.

    C language only, not POSIX here, please.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Sep 2, 2004
    #9
  10. (Kenny McCormack) writes:
    > In article <ch5q1m$26qd$>,
    > Richard Tobin <> wrote:
    > >In article <ch5p44$c1l$>,
    > >Kenny McCormack <> wrote:
    > >
    > >>>How exactly would you present a 50K argument to your program?

    > >
    > >>The short answer is: ls *

    > >
    > >That presents lots of smallish arguments, which isn't exactly what the OP
    > >was asking about. I think a single 50k argument would be very unusual.
    > >
    > >-- Richard

    >
    > Um, it is the total size (the sum of all the args lengths) that matters.


    The original poster asked about the maximum size of the string pointed
    to by argv[1].

    Any limits on argument size are system-specific and off-topic for
    comp.lang.c. comp.unix.programer is probably a good place to ask.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Sep 2, 2004
    #10
  11. Richard Tobin <> wrote:
    > In article <ch5p44$c1l$>,
    > Kenny McCormack <> wrote:
    >
    >>>How exactly would you present a 50K argument to your program?

    >
    >>The short answer is: ls *

    >
    > That presents lots of smallish arguments, which isn't exactly what the OP
    > was asking about. I think a single 50k argument would be very unusual.


    Unusual, yes. A sign of bad programming/planning, probably.
    Always avoidable in any real-world case, probably.
    But, still:

    awk "`cat big_awk_program`"

    Yes yes, "-f" would be better! And the equivalent of "-f" would
    probably be a better solution for the OP: the size limits of the
    filesystem are likely to be much larger than the limits of the
    commandline (and environment variables).

    --Benjamin
    Benjamin Ketcham, Sep 3, 2004
    #11
  12. Jack Klein <> wrote in message news:<>...
    > On 1 Sep 2004 09:02:41 -0700, (Mark R.Bannister)
    > wrote in comp.lang.c:
    >
    > > -berlin.de wrote in message news:<>...
    > > > James <> wrote:
    > > > > consider :
    > > > > int main (int argc, char * argv [ ]) {

    >
    > > > > }

    >
    > > > > In exec (2) ; Whose arguments which are passed to main.

    >
    > > > > What is the maximum size of the string.
    > > > > argv[1] = "hello........." ;

    >
    > > > > How long can argv[1] point to. even though i know argv is 4 bytes
    > > > > pointer. How long can the string be ?.

    >
    > > > > I just want to send a 50K string as my process arguments (main's
    > > > > args)
    > > > > when i fork and exec.

    >
    > > > > Is it possible ?. Does standard say something on this ?.

    >
    > > > > Are there any limitations ?.
    > > >
    > > > As far as I can tell, there's no requirement for the size of it in
    > > > the C standard (and I can't see any good reason why the standard
    > > > should require an upper limit). On the other hand, the operating
    > > > system will probably put a limit on the maximum size. E.g. the
    > > > POSIX standard SUSv3 requires that argv can use at least 4096 bytes
    > > > (but many Unices allow a lot more).
    > > >
    > > > Regards, Jens

    > >
    > > There isn't a limit on the length of an individual argument, only on
    > > the length of the entire argument line has the ARG_MAX limit imposed
    > > on it, defined in limits.h. The following makes an interesting
    > > comparison on the size of ARG_MAX across various systems:

    >
    > Perhaps you thought you were responding in comp.unix.programmer, and
    > not comp.lang.c. According to the C standard, a conforming compiler
    > is not allowed to define a macro in <limits.h>.
    >
    > C language only, not POSIX here, please.


    Well excuse me for giving a real world answer.
    Mark R.Bannister, Sep 3, 2004
    #12
  13. In article <>,
    Mark R.Bannister <> wrote:
    ....
    >Well excuse me for giving a real world answer.


    The real world is OT here. I thought you understood that by now.
    Kenny McCormack, Sep 3, 2004
    #13
  14. (Mark R.Bannister) writes:
    > Jack Klein <> wrote in message
    > news:<>...

    [...]
    > > Perhaps you thought you were responding in comp.unix.programmer, and
    > > not comp.lang.c. According to the C standard, a conforming compiler
    > > is not allowed to define a macro in <limits.h>.
    > >
    > > C language only, not POSIX here, please.

    >
    > Well excuse me for giving a real world answer.


    Which real world would that be? There are plenty of real world
    systems that support C but not POSIX, and there are newsgroups where
    POSIX is topical.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Sep 3, 2004
    #14
  15. James

    azad2010

    Joined:
    May 5, 2012
    Messages:
    1
    Plz help me

    Hi
    Do u have any solution to solve your problem?
    I want to send one argument to c app but length of it is 480 characters and app dose not work
    azad2010, May 5, 2012
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,547
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    5,911
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,608
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    882
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. jab3

    char **argv & char *argv[]

    jab3, Dec 4, 2004, in forum: C Programming
    Replies:
    5
    Views:
    646
    Chris Torek
    Dec 8, 2004
Loading...

Share This Page