The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > AIX
.
google unix.com



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
_/proc/stat vs /proc/uptime coderd UNIX for Dummies Questions & Answers 0 05-08-2009 02:37 PM
Error in script to automate the daily monitoring process of UNIX server and it's proc rdhaprakasam Shell Programming and Scripting 8 04-21-2009 10:05 AM
twitter-cmdline 1.02 (Default branch) iBot Software Releases - RSS News 0 06-17-2008 01:20 PM
How to call a proc file from *.c program? pat_and_cami Linux 4 02-15-2006 02:24 AM
runlevel from cmdline or lilo? odys Linux 2 02-06-2006 04:22 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 4 Weeks Ago
tbk tbk is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 1
AIX equivalent to /proc/self/cmdline to get process name from C++ program

Hi,
I'm porting some old C++ code (that I didn't write) from Linux to AIX and have run into a problem in getting the process name from within the code when it is run on AIX. Basically the code is getting the process name so it can then return it to the rest of the code as argv[0]. This code is trying to name logfiles using the process name and is called by many other classes.
The OS is: powerpc-ibm-aix5.3.0.0
The gcc is: gcc version 4.2.0

The code is below:

Code:
static const std::string getArg0(void)
    {
#if defined(__hpux__) || defined(__hpux)
    extern char** __argv_value; // see man crt0 on HP-UX.
    return __argv_value[0];
#elif defined(__linux__)
    static std::string argv;
    static bool first = true;
    if (first)
        {
        first = false;
        std::ifstream is("/proc/self/cmdline");
        if (!is)
            argv = "unknown";
        else
            {
            std::ostringstream os;
            char buf;
            while (true)
                {
                is.get(buf);
                if (!is)
                    break;
                if (!isspace(buf))
                    os << buf;
                else
                    break;
                }
            os << std::ends;
            argv = os.str();
            is.close();
            }
        }
        return argv;
#elif defined(_AIX)
    extern char** argv;
    return argv[0];
#else
    return "unknown";
#endif
    }

// -- public -----------------------------------------------------------------
// getProcName()
//
// Determine the process name and return it.
//
// -- implementation ---------------------------------------------------------
// Since this is called before main(), we can't use argv.  But the C run time
// startup code sets argv from the global __argv_value, so just use that.
// ---------------------------------------------------------------------------
TextString LogStream::getProcName(bool useFullPath)
    {
      // LAB - GCC upgrade syntax change
    static TextString fullName(getArg0().c_str());
    static TextString leafOnly(basename((char *)fullName.stringPtr()));
    return useFullPath ? fullName : leafOnly;
    }
I intially added "|| _AIX" to the linux block above but since AIX doesn't have /proc/self it failed and all my logfiles are named unknown*. I have tried several different separate blocks for AIX, but after hours of searching for how to get the process name I've hit a wall. I am able to compile, but always get an undefined error on the link. How do I duplicate the above blocks used for linux and (ancient hp block) for AIX?

Any help is greatly appreciated! Thanks..
Tom
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0