本文整理汇总了C++中Child::getpid方法的典型用法代码示例。如果您正苦于以下问题:C++ Child::getpid方法的具体用法?C++ Child::getpid怎么用?C++ Child::getpid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Child
的用法示例。
在下文中一共展示了Child::getpid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mypid
int
run_main (int argc, ACE_TCHAR *argv[])
{
parse_args (argc, argv);
// Child process code.
if (child_nr >= 0)
{
ACE_TCHAR lognm[MAXPATHLEN];
int mypid (ACE_OS::getpid ());
ACE_OS::sprintf(lognm,
ACE_TEXT ("RW_Process_Mutex_Test-child-%d"),
(int)mypid);
ACE_START_TEST (lognm);
if (child_nr == 0)
writer ();
else
reader (child_nr);
ACE_END_LOG;
}
else
{
ACE_START_TEST (ACE_TEXT ("RW_Process_Mutex_Test"));
// Although it should be safe for each process to construct and
// destruct the rw lock, this can disturb other process still
// using the lock. This is not really correct, and should be
// looked at, but it gets things moving.
// Also see Process_Mutex_Test.cpp for similar issue.
ACE_RW_Process_Mutex mutex (mutex_name.c_str ());
// Make sure the constructor succeeded
if (ACE_LOG_MSG->op_status () != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Parent, mutex %s %p\n"),
mutex_name.c_str (),
ACE_TEXT ("ctor")));
}
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
static const ACE_TCHAR* format = ACE_TEXT ("%ls -c %d -p %u -n %ls");
#else
static const ACE_TCHAR* format = ACE_TEXT ("%s -c %d -p %u -n %s");
#endif /* !ACE_WIN32 && ACE_USES_WCHAR */
// The parent process reads time ranges sent from the children via
// UDP. Grab an unused UDP port to tell the children to send to.
ACE_INET_Addr me;
ACE_SOCK_Dgram sock;
if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Socket %p\n"),
ACE_TEXT ("open")),
-1);
sock.get_local_addr (me);
ACE_TCHAR me_str[80];
me.addr_to_string (me_str, 80);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Receiving on %s\n"), me_str));
// Spawn 1 writer and 3 reader processes that will contend for the
// lock.
Child writer;
Child readers[Nr_Processes - 1];
int i;
for (i = 0; i < Nr_Processes; i++)
{
Child *child = (i == 0 ? &writer : &readers[i-1]);
ACE_Process_Options options;
options.command_line (format,
argc > 0 ? argv[0] : ACE_TEXT ("RW_Process_Mutex_Test"),
i,
(unsigned int)me.get_port_number (),
mutex_name.c_str ());
if (child->spawn (options) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("spawn of child %d %p\n"),
i,
ACE_TEXT ("failed")),
-1);
}
else
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Child process %d has pid = %d.\n"),
i,
(int)(child->getpid ())));
}
}
// Keep reading time ranges reported from the children until all the
// children have exited. Alternate between checking for a range and
// checking for exits.
int processes = Nr_Processes;
Child *children[Nr_Processes];
for (i = 0; i < Nr_Processes; i++)
children[i] = (i == 0 ? &writer : &readers[i-1]);
Range_Report report;
ACE_Time_Value poll (0);
ACE_INET_Addr from;
//.........这里部分代码省略.........