Cabon? Cocoa? Java? C? C++? Ruby? Perl? Python? php? Lisp? ADA? FoxPro? Visual Basic? Each would have their own function/API for listing that, but you didn't mention what programming language you're using.
If you want to use a UNIX program call, then you can simply use 'lsof'.