int run_main (int argc, ACE_TCHAR *argv[]) { parse_args (argc, argv); // Child process code. if (child_process) { ACE_TCHAR lognm[MAXPATHLEN]; int mypid (ACE_OS::getpid ()); ACE_OS::snprintf (lognm, MAXPATHLEN, ACE_TEXT ("Process_Mutex_Test-child-%d"), mypid); ACE_START_TEST (lognm); acquire_release (); ACE_END_LOG; } else { ACE_START_TEST (ACE_TEXT ("Process_Mutex_Test")); # if !defined( ACE_HAS_SYSV_IPC) || defined(ACE_USES_MUTEX_FOR_PROCESS_MUTEX) // When Process_Mutex is pthreads based, then the owner of mutex destroys it // in destructor. This may disturb the other processes which still uses the // mutex. It is safer then to hold the mutex in main process, and destroy it after // children finish. This is temporary solution, and in future pthread base // Process_Mutex shall control the destruction of mutex better. ACE_Process_Mutex mutex( mutex_name ); # endif #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) static const ACE_TCHAR* format = ACE_TEXT ("%ls -c -n %ls%ls"); #else static const ACE_TCHAR* format = ACE_TEXT ("%s -c -n %s%s"); #endif /* !ACE_WIN32 && ACE_USES_WCHAR */ ACE_Process_Options options; #ifndef ACE_LACKS_VA_FUNCTIONS options.command_line (format, argc > 0 ? argv[0] : ACE_TEXT ("Process_Mutex_Test"), mutex_name, release_mutex == 0 ? ACE_TEXT (" -d") : ACE_TEXT ("")); #else ACE_UNUSED_ARG (format); #endif #ifdef ACE_HAS_PROCESS_SPAWN // Spawn <n_processes> child processes that will contend for the // lock. ACE_Process children[n_processes]; size_t i; for (i = 0; i < n_processes; i++) { // Spawn the child process. if (children[i].spawn (options) == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("spawn of client %d failed\n"), i), -1); } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Parent spawned child process with pid = %d.\n"), children[i].getpid ())); } // Give the newly spawned child process a chance to start... // David Levine thinks this sleep() is required because // calling ::waitpid () before a fork'ed child has actually // been created may be a problem on some platforms. It's // not enough for fork() to have returned to the parent. ACE_OS::sleep (1); } for (i = 0; i < n_processes; i++) { ACE_exitcode child_status; // Wait for the child processes we created to exit. int wait_result = children[i].wait (&child_status); ACE_TEST_ASSERT (wait_result != -1); if (child_status == 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Child %d finished ok\n"), children[i].getpid ())); else ACE_ERROR ((LM_ERROR, ACE_TEXT ("Child %d finished with status %d\n"), children[i].getpid (), child_status)); } #endif // ACE_HAS_PROCESS_SPAWN ACE_Process_Mutex::unlink (mutex_name); ACE_END_TEST; } return 0; }
int run_main (int argc, ACE_TCHAR *argv[]) { #if defined (ACE_LACKS_FORK) ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); ACE_START_TEST (ACE_TEXT ("Process_Semaphore_Test")); ACE_ERROR ((LM_INFO, ACE_TEXT ("fork is not supported on this platform\n"))); ACE_END_TEST; #else parse_args (argc, argv); // Child process code. if (child_process) { ACE_START_TEST (ACE_TEXT ("Process_Semaphore_Test-child")); acquire_release (); ACE_END_LOG; } else { ACE_START_TEST (ACE_TEXT ("Process_Semaphore_Test")); ACE_TString exe_sub_dir; const char *subdir_env = ACE_OS::getenv ("ACE_EXE_SUB_DIR"); if (subdir_env) { exe_sub_dir = ACE_TEXT_CHAR_TO_TCHAR (subdir_env); exe_sub_dir += ACE_DIRECTORY_SEPARATOR_STR; } ACE_Process_Options options; options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT ("%sProcess_Semaphore_Test") ACE_PLATFORM_EXE_SUFFIX ACE_TEXT (" -c -i %d"), exe_sub_dir.c_str(), iterations); // Spawn a child process that will contend for the // lock. ACE_Process child; // Spawn the child process. int result = child.spawn (options); ACE_TEST_ASSERT (result != -1); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Parent spawned child process with pid = %d.\n"), child.getpid ())); // start test acquire_release (); ACE_exitcode child_status; // Wait for the child processes we created to exit. ACE_TEST_ASSERT (child.wait (&child_status) != -1); if (child_status == 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Child %d finished ok\n"), child.getpid ())); else ACE_ERROR ((LM_ERROR, ACE_TEXT ("Child %d finished with status %d\n"), child.getpid (), child_status)); ACE_END_TEST; } #endif /* ! ACE_LACKS_FORK */ return 0; }
int run_main (int argc, ACE_TCHAR *argv[]) { #if defined (ACE_LACKS_FORK) ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); ACE_START_TEST (ACE_TEXT ("Process_Mutex_Test")); ACE_ERROR ((LM_INFO, ACE_TEXT ("fork is not supported on this platform\n"))); ACE_END_TEST; #else /* ! ACE_LACKS_FORK */ parse_args (argc, argv); // Child process code. if (child_process) { ACE_APPEND_LOG ("Process_Mutex_Test-children"); acquire_release (); ACE_END_LOG; } else { ACE_START_TEST (ACE_TEXT ("Process_Mutex_Test")); ACE_INIT_LOG ("Process_Mutex_Test-children"); ACE_Process_Options options; if (release_mutex == 0) options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT ("Process_Mutex_Test") ACE_PLATFORM_EXE_SUFFIX ACE_TEXT (" -c -n %s -d"), ACE_TEXT_CHAR_TO_TCHAR (mutex_name)); else options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT ("Process_Mutex_Test") ACE_PLATFORM_EXE_SUFFIX ACE_TEXT (" -c -n %s"), ACE_TEXT_CHAR_TO_TCHAR (mutex_name)); // Spawn <n_processes> child processes that will contend for the // lock. ACE_Process children[n_processes]; size_t i; for (i = 0; i < n_processes; i++) { // Spawn the child process. int result = children[i].spawn (options); ACE_ASSERT (result != -1); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Parent spawned child process with pid = %d.\n"), children[i].getpid ())); // Give the newly spawned child process a chance to start... // David Levine thinks this sleep() is required because // calling ::waitpid () before a fork'ed child has actually // been created may be a problem on some platforms. It's // not enough for fork() to have returned to the parent. ACE_OS::sleep (1); } for (i = 0; i < n_processes; i++) { ACE_exitcode child_status; // Wait for the child processes we created to exit. ACE_ASSERT (children[i].wait (&child_status) != -1); if (child_status == 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Child %d finished ok\n"), children[i].getpid ())); else ACE_ERROR ((LM_ERROR, ACE_TEXT ("Child %d finished with status %d\n"), children[i].getpid (), child_status)); } ACE_END_TEST; } #endif /* ! ACE_LACKS_FORK */ return 0; }