Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: base/process_util.h

Issue 14497: POSIX: don't leak FDs when launching child Processes. (Closed)
Patch Set: Fix Windows Compilation Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/multiprocess_test.h ('k') | base/process_util_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file/namespace contains utility functions for enumerating, ending and 5 // This file/namespace contains utility functions for enumerating, ending and
6 // computing statistics of processes. 6 // computing statistics of processes.
7 7
8 #ifndef BASE_PROCESS_UTIL_H_ 8 #ifndef BASE_PROCESS_UTIL_H_
9 #define BASE_PROCESS_UTIL_H_ 9 #define BASE_PROCESS_UTIL_H_
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 int GetCurrentProcId(); 59 int GetCurrentProcId();
60 60
61 // Returns the ProcessHandle of the current process. 61 // Returns the ProcessHandle of the current process.
62 ProcessHandle GetCurrentProcessHandle(); 62 ProcessHandle GetCurrentProcessHandle();
63 63
64 // Returns the unique ID for the specified process. This is functionally the 64 // Returns the unique ID for the specified process. This is functionally the
65 // same as Windows' GetProcessId(), but works on versions of Windows before 65 // same as Windows' GetProcessId(), but works on versions of Windows before
66 // Win XP SP1 as well. 66 // Win XP SP1 as well.
67 int GetProcId(ProcessHandle process); 67 int GetProcId(ProcessHandle process);
68 68
69 #if defined(OS_POSIX)
70 // Returns the maximum number of files that a process can have open.
71 // Returns 0 on error.
72 int GetMaxFilesOpenInProcess();
73 #endif
74
69 #if defined(OS_WIN) 75 #if defined(OS_WIN)
70 // Runs the given application name with the given command line. Normally, the 76 // Runs the given application name with the given command line. Normally, the
71 // first command line argument should be the path to the process, and don't 77 // first command line argument should be the path to the process, and don't
72 // forget to quote it. 78 // forget to quote it.
73 // 79 //
74 // If wait is true, it will block and wait for the other process to finish, 80 // If wait is true, it will block and wait for the other process to finish,
75 // otherwise, it will just continue asynchronously. 81 // otherwise, it will just continue asynchronously.
76 // 82 //
77 // Example (including literal quotes) 83 // Example (including literal quotes)
78 // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\" 84 // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\"
79 // 85 //
80 // If process_handle is non-NULL, the process handle of the launched app will be 86 // If process_handle is non-NULL, the process handle of the launched app will be
81 // stored there on a successful launch. 87 // stored there on a successful launch.
82 // NOTE: In this case, the caller is responsible for closing the handle so 88 // NOTE: In this case, the caller is responsible for closing the handle so
83 // that it doesn't leak! 89 // that it doesn't leak!
84 bool LaunchApp(const std::wstring& cmdline, 90 bool LaunchApp(const std::wstring& cmdline,
85 bool wait, bool start_hidden, ProcessHandle* process_handle); 91 bool wait, bool start_hidden, ProcessHandle* process_handle);
86 #elif defined(OS_POSIX) 92 #elif defined(OS_POSIX)
87 // Runs the application specified in argv[0] with the command line argv. 93 // Runs the application specified in argv[0] with the command line argv.
88 // Both the elements of argv and argv itself must be terminated with a null 94 // Both the elements of argv and argv itself must be terminated with a null
89 // byte. 95 // byte.
96 // Before launching all FDs open in the parent process will be marked as
97 // close-on-exec. |fds_to_remap| defines a mapping of src fd->dest fd to
98 // propagate FDs into the child process.
90 // 99 //
91 // As above, if wait is true, execute synchronously. The pid will be stored 100 // As above, if wait is true, execute synchronously. The pid will be stored
92 // in process_handle if that pointer is non-null. 101 // in process_handle if that pointer is non-null.
93 // 102 //
94 // Note that the first argument in argv must point to the filename, 103 // Note that the first argument in argv must point to the filename,
95 // and must be fully specified. 104 // and must be fully specified.
105 typedef std::vector<std::pair<int, int> > file_handle_mapping_vector;
96 bool LaunchApp(const std::vector<std::string>& argv, 106 bool LaunchApp(const std::vector<std::string>& argv,
107 const file_handle_mapping_vector& fds_to_remap,
97 bool wait, ProcessHandle* process_handle); 108 bool wait, ProcessHandle* process_handle);
98 #endif 109 #endif
99 110
100 // Execute the application specified by cl. This function delegates to one 111 // Execute the application specified by cl. This function delegates to one
101 // of the above two platform-specific functions. 112 // of the above two platform-specific functions.
102 bool LaunchApp(const CommandLine& cl, 113 bool LaunchApp(const CommandLine& cl,
103 bool wait, bool start_hidden, ProcessHandle* process_handle); 114 bool wait, bool start_hidden, ProcessHandle* process_handle);
104 115
105 // Used to filter processes by process ID. 116 // Used to filter processes by process ID.
106 class ProcessFilter { 117 class ProcessFilter {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // overflow. Has no effect if the OS doesn't provide the necessary facility. 329 // overflow. Has no effect if the OS doesn't provide the necessary facility.
319 void EnableTerminationOnHeapCorruption(); 330 void EnableTerminationOnHeapCorruption();
320 331
321 // If supported on the platform, and the user has sufficent rights, increase 332 // If supported on the platform, and the user has sufficent rights, increase
322 // the current process's scheduling priority to a high priority. 333 // the current process's scheduling priority to a high priority.
323 void RaiseProcessToHighPriority(); 334 void RaiseProcessToHighPriority();
324 335
325 } // namespace base 336 } // namespace base
326 337
327 #endif // BASE_PROCESS_UTIL_H_ 338 #endif // BASE_PROCESS_UTIL_H_
OLDNEW
« no previous file with comments | « base/multiprocess_test.h ('k') | base/process_util_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698