LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-23-2009, 06:28 AM   #1
shashank929
LQ Newbie
 
Registered: Apr 2009
Posts: 10

Rep: Reputation: 0
ftw : file tree walk recursion level problem


ftw function of ftw.h is a recursive implementation for recursively walking down a directory tree. I want to know how deep can the recursion level be.
I am making a program using ftw in which I may have to give the root directory also for traversing. So how can I know that at what level of subdirectories the function will fail?? TIA
 
Old 04-23-2009, 08:31 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi

I'm not 100% sure about this, but the stack is usually megabytes in size (8Mb size is default, but it can be set with "ulimit -s"). So unless it's set very low, or other parts of the program uses a lot of stack space, you can't reach that limit. MAX_PATH is usually 256 bytes, which means you can't go deeper than about 128 directories, and that doesn't take much stack space.

Edit: I was mistaken, directories can be a lot deeper than I thought. But the stack still has a lot of space and can hold directories thousands of levels deep..

Last edited by Guttorm; 04-23-2009 at 08:37 AM.
 
Old 04-23-2009, 10:52 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by Guttorm View Post
[...] MAX_PATH is usually 256 bytes
256 sounds low...
So I tried it (on ubuntu 8.10 i386):
Code:
hko:/tmp$ cat path_max.c
#include <stdio.h>
#include <limits.h>

int main()
{
    printf("PATH_MAX = %d\n", PATH_MAX);
    return 0;
}
hko:/tmp$ gcc -Wall -o path_max path_max.c
hko:/tmp$ ./path_max
PATH_MAX = 4096
This is just as a side note. Even with this much bigger number for PATH_MAX, the point you want to make is still valid I think.

Last edited by Hko; 04-23-2009 at 10:55 AM.
 
Old 04-24-2009, 01:04 AM   #4
shashank929
LQ Newbie
 
Registered: Apr 2009
Posts: 10

Original Poster
Rep: Reputation: 0
thanks

thanks a lot guys.... that answered my question
I need to understand one more thing
PATH_MAX is the maximum path length allowed on the system....can anyone change it on the system and if he does then what will be the maximum limit of the directory level.
On my system also PATH_MAX is 4096
 
Old 04-24-2009, 01:23 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
That would probably require modifying the C-code of fundamental parts of the operating system like libc and/or the kernel.

So, pretty unlikely that your program will be run on such a system. I suppose the find program also depends on this max directory tree recursion limit.
 
Old 04-24-2009, 05:00 AM   #6
shashank929
LQ Newbie
 
Registered: Apr 2009
Posts: 10

Original Poster
Rep: Reputation: 0
okk...thanks...

Also, since PATH_MAX is 4096 on my system... so how much maximum level of the directories on my system can be

Last edited by shashank929; 04-24-2009 at 07:40 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ftw- can please someone explain this to me? panchosansa Programming 3 10-13-2006 08:44 PM
emacs in run level 3 then switch to X (level 7) then back to level 3 dsoliver Slackware 3 09-01-2006 03:31 AM
Base Case Recursion Problem Mistro116@yahoo.com Programming 7 11-27-2005 10:21 PM
file tree question chokeX Linux - Newbie 1 11-03-2005 08:12 PM
tar: '--no-recursion' option doesn't prevent recursion Earl Parker II Slackware 12 08-17-2004 02:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration