Max Size of argv[1] ???

J

James

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
 
J

Jens.Toerring

James said:
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
 
A

Andrew Au \(Newsgroup\)

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

James said:
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
 
M

Mark R.Bannister

James said:
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.
 
J

Joe Wright

James said:
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.
 
K

Kenny McCormack

Joe Wright said:
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()).
 
R

Richard Tobin

How exactly would you present a 50K argument to your program?
[/QUOTE]
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
 
K

Kenny McCormack

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[/QUOTE]

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

Jack Klein

James said:
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.
 
K

Keith Thompson

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.
 
B

Benjamin Ketcham

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.[/QUOTE]

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
 
M

Mark R.Bannister

Jack Klein said:
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.
 
K

Keith Thompson

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.
 
Joined
May 5, 2012
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top