Here is the enhancement that we found very useful.
Consider a process that spawns a number of processes using a same exeutable
name but with different arguments <say svc.conf file..>. Depending on the
arguments, each process does different things.
Currently <ACE_Process::spawn> calls <execvp> with argv[0] as the exeutable
name. Therefore, if you do a <ps> command now, all these processes will look
the same, since they are all launched with the same command.
But for <execvp> call, you could actually give a different executable name
and a different argv[0]. This helps us to have the name for a process to be
different from the executable name. In this case, <ps> command will show the
processes with different argv[0] names.
I have added a method called <path> to ACE_Process_Options to specify the
executable name. If you do not call <path> method, argv[0] is taken as the
executable name.
I have attached the diff's to Proces.{h,cpp,i} files so that you can specify
executable name to be other than argv[0].
This should be useful for others too. DOC folks, please feel free to
integrate this, when you get a chance.
Thanks
Alex
==== //depot/ACE_wrappers/ace/Process.h#1 -
/home2/alex/ACE_wrappers/ace/Process.h ====
@@ -123,6 +123,13 @@
int command_line (LPCTSTR const argv[]);
// Same as above in argv format. <argv> must be null terminated.
+ void path (LPCTSTR path);
+ // Specify the full path or relative path or just the executable
+ // name for the process. If this is set, then <path> will be used to
+ // create the process instead of arv[0] set in the command
+ // line. This is here so that you can supply something other than
+ // executable name as argv[0].
+
u_long creation_flags (void) const;
// Get the creation flags.
void creation_flags (u_long);
@@ -137,6 +144,10 @@
// Buffer of command-line options. Returns exactly what was passed
// to this->command_line.
+ LPCTSTR path (void);
+ // Return the path. If <path> is not called, it will return the
+ // argv[0].
+
LPTSTR env_buf (void);
// Null-terminated buffer of null terminated strings. Each string
// is an environment assignment "VARIABLE=value". This buffer
@@ -277,6 +288,10 @@
LPTSTR command_line_argv_[MAX_COMMAND_LINE_OPTIONS];
// Argv-style command-line arguments.
+
+ TCHAR path_[MAXPATHLEN + 1];
+ // Path for the process. Relative path or absolute path or just the
+ // program name.
};
============================================================================
==============
==== //depot//ACE_wrappers/ace/Process.cpp#1 -
/home2/alex/ACE_wrappers/ace/Process.cpp ====
@@ -71,7 +71,7 @@
if (options.env_argv ()[0] == 0)
// command-line args
- this->child_id_ = ACE_OS::execvp (options.command_line_argv ()[0],
+ this->child_id_ = ACE_OS::execvp (options.path (),
options.command_line_argv ());
else
{
@@ -85,14 +85,14 @@
// Now the forked process has both inherited variables and the
// user's supplied variables.
- this->child_id_ = ACE_OS::execvp (options.command_line_argv ()[0],
+ this->child_id_ = ACE_OS::execvp (options.path (),
options.command_line_argv ());
}
return this->child_id_;
#else /* ACE_WIN32 */
// Fork the new process.
- this->child_id_ = ACE::fork (options.command_line_argv ()[0],
+ this->child_id_ = ACE::fork (options.path (),
options.avoid_zombies ());
// If we're not supposed to exec, return the process id.
@@ -131,7 +131,7 @@
if (options.env_argv ()[0] == 0)
// command-line args
- result = ACE_OS::execvp (options.command_line_argv ()[0],
+ result = ACE_OS::execvp (options.path (),
options.command_line_argv ());
else
{
@@ -151,7 +151,7 @@
// Now the forked process has both inherited variables and
// the user's supplied variables.
- result = ACE_OS::execvp (options.command_line_argv ()[0],
+ result = ACE_OS::execvp (options.path (),
options.command_line_argv ());
#endif /* ghs */
}
@@ -251,6 +251,7 @@
LPTSTR[mea]);
environment_buf_[0] = '\0';
environment_argv_[0] = 0;
+ path_[0] = '\0';
#if defined (ACE_WIN32)
ACE_OS::memset ((void *) &this->startup_info_,
============================================================================
==========
==== //depot/ACE_wrappers/ace/Process.i#1 -
/home2/alex/ACE_wrappers/ace/Process.i ====
@@ -169,6 +169,15 @@
return command_line_buf_;
}
+ACE_INLINE LPCTSTR
+ACE_Process_Options::path (void)
+{
+ if (path_[0] == '\0')
+ this->path (this->command_line_argv ()[0]);
+
+ return this->path_;
+}
+
ACE_INLINE LPTSTR
ACE_Process_Options::working_directory (void)
{
@@ -189,7 +198,13 @@
ACE_OS::strcpy (working_directory_, wd);
#else
ACE_UNUSED_ARG (wd);
-#endif /* !ACE_HAS_WINCE */
+#endif /* !ACE_HAS_WINCE */
+}
+
+ACE_INLINE void
+ACE_Process_Options::path (LPCTSTR p)
+{
+ ACE_OS::strcpy (this->path_, p);
}
#if defined (ACE_HAS_WINCE)
@@ -211,15 +226,15 @@
ACE_INLINE int
ACE_Process_Options::setenv (LPCTSTR variable_name,
- LPCTSTR format, ...)
+ LPCTSTR format, ...)
{
return -1;
}
ACE_INLINE int
ACE_Process_Options::set_handles (ACE_HANDLE std_in,
- ACE_HANDLE std_out,
- ACE_HANDLE std_err)
+ ACE_HANDLE std_out,
+ ACE_HANDLE std_err)
{
ACE_UNUSED_ARG (std_in);
ACE_UNUSED_ARG (std_out);
Thanks
Alex
--
http://www.sylantro.com
408-626-2227 (Work)
408-559-1933 (Home)
>Here is the enhancement that we found very useful.
Great, thanks!
>Consider a process that spawns a number of processes using a same exeutable
>name but with different arguments <say svc.conf file..>. Depending on the
>arguments, each process does different things.
>
>Currently <ACE_Process::spawn> calls <execvp> with argv[0] as the exeutable
>name. Therefore, if you do a <ps> command now, all these processes will look
>the same, since they are all launched with the same command.
>
>But for <execvp> call, you could actually give a different executable name
>and a different argv[0]. This helps us to have the name for a process to be
>different from the executable name. In this case, <ps> command will show the
>processes with different argv[0] names.
>
>I have added a method called <path> to ACE_Process_Options to specify the
>executable name. If you do not call <path> method, argv[0] is taken as the
>executable name.
>
>I have attached the diff's to Proces.{h,cpp,i} files so that you can specify
>executable name to be other than argv[0].
Thanks, that looks quite useful, so I've added it for the next beta
release of ACE! However, rather than calling it "path" (which is a
misnomer), I've called it "process_name". I hope that doesn't break
too much of your code!
Take care,
Doug
--
Dr. Douglas C. Schmidt, Associate Professor TEL: (949) 824-1901
Dept of Electrical & Computer Engineering FAX: (949) 824-2321
616E Engineering Tower WEB: www.eng.uci.edu/~schmidt/
University of Calfornia, Irvine, 92697-2625 NET: sch...@uci.edu