There are not strict limits on the length of the pipeline (that is the number of commands composing it). However, the maximum number of processes can be limited with setrlimit(2) RLIMIT_NPROC
and each system has some absolute limit. Likewise, the number of file descriptors can be limited with RLIMIT_NOFILE
Also, your shell will call pipe(2), and that syscall can fail (and this is practically limiting).
BTW, the maximal command line should better not be a hardwired limit (it can be changed somehow). The limitation is when execve(2) fails. And you could use sysconf(_SC_ARG_MAX)
-see sysconf(3)- to query something related.
At last proc(5) could be used to query some related thresholds, e.g. using /proc/sys/fs/pipe-max-size
, /proc/sys/kernel/core_pipe_limit
, etc.
The bottom line is that you should not build in any wired-in limits in your shell. You should just manage resources and handle failure (of syscalls(2)
and of standard functions like malloc(3) ...). Avoid defining arbitrary builtin limits like your MAX_CMD_LEN
(BTW, the exact figure is not the same on my Debian/Sid/x86-64 running a kernel 3.17 which I did compile myself).