- What is a `**ppEnum`? - 4 Updates
- Windows does overcommit stacks ! - 4 Updates
- session ID - 13 Updates
- what is the best way to get microseconds of time on Windows in C or C++ ? - 1 Update
Ralf Fassel <ralfixx@gmx.de>: Nov 15 10:17AM +0100 * T <T@invalid.invalid> | A pointer to a pointer. Geez! I am going to write that up in my C | notes that I use with native call. In c++, you have references to change a variable passed 'down' to a function. But in C it is either return-value (which in your case is already taken by the HRESULT success/failure indication), globals or pointers. So if you want to change a pointer, you need to pass the address of that pointer, i.e. pointer-to-pointer. R' |
"Öö Tiib" <ootiib@hot.ee>: Nov 15 04:24AM -0800 On Tuesday, 15 November 2022 at 11:18:10 UTC+2, Ralf Fassel wrote: > already taken by the HRESULT success/failure indication), globals or > pointers. So if you want to change a pointer, you need to pass the > address of that pointer, i.e. pointer-to-pointer. Yes but note that the question was about usage of Windows API COM interface subsystem in Raku. That interface is designed to be compatible with C to ensure it is possible to integrate with any language that can interoperate with C. The result is not outright "three star interface" but pointers to pointers are common enough. The MS ATL libraries provide some C++ wrappers to abstract those pointers away but I'm unsure how compatible Perl or Raku is with C++ templates from ATL (likely not at all). |
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Nov 15 02:04PM +0100 On 14 Nov 2022 20:02, T wrote: > "Listing" should not require administrator privileges, > but Windows is not as smart as Linux ("dnf" lets > query without being root, etc.). Try command > wmic volume list brief There are also others, as I recall. > so poop (not my exact word). Meaning that > I am going to have to run as administrator > anyway, No you don't. See above. > question answered anymore, other that > for leaning for the future. > So everyone can stop trying to teach me now. Hm! > And thank you for all your gracious effort! Well, thanks. :) > A pointer to a pointer. Geez! I am going > to write that up in my C notes that I use > with native call. Yeah. The nice thing about C++ is that you /can/ wrap such things in far more convenient, well, wrappers. And if you're lucky Someone Else(tm) will have done that for you already, so you can just use the stuff. The flip side is that especially reusable (as opposed to /ad hoc/) more convenient wrappers can be a heck of a lot of code. But. - Alf |
T <T@invalid.invalid>: Nov 15 08:28AM -0800 On 11/15/22 05:04, Alf P. Steinbach wrote: > wmic volume list brief Hi Alf, Diskpart (as administrator) is the only utility that will list mirror volumes. Note the differences between the report for J: below -T C>diskpart Microsoft DiskPart version 10.0.22621.1 Copyright (C) Microsoft Corporation. On computer: KVM-W11 DISKPART> list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- -------- Volume 0 J BACKUP NTFS Mirror 69 MB Healthy ... >wmic volume list brief Capacity DriveType FileSystem FreeSpace Label Name 73396224 3 NTFS 58589184 BACKUP F:\ 63637024768 3 NTFS 33665376256 C:\ 661647360 3 NTFS 87003136 \\?\Volume{87e27543-bc3d-4f97-b7bc-321d8451c994}\ 100663296 3 FAT32 67761152 \\?\Volume{d8fe8f8c-3c0b-4164-b282-da7270e7e411}\ 72347648 3 NTFS 57581568 BACKUP J:\ 4335380480 5 UDF 0 22000.1_X64_EN-US D:\ 532060160 5 CDFS 0 virtio-win-0.1.225 E:\ 1694498816 5 CDFS 0 Fedora-Xfce-Live G:\ |
"Öö Tiib" <ootiib@hot.ee>: Nov 15 04:09AM -0800 On Monday, 14 November 2022 at 23:03:58 UTC+2, Bonita Montero wrote: > were committed without being physically assigned, then I would need at > least a lot of swap, which would keep the available swap in case the > committed pages were also written. The overcommit involves committing. Reserve is not commit. Letting software to reserve more than is physically available is allowing over-reserve not doing overcommit. The outcome of over-reserve and overcommit is different. Overcommit results with OOM killer killing processes, over-reserve results with processes attempting to commit getting exceptions. |
Bonita Montero <Bonita.Montero@gmail.com>: Nov 15 02:23PM +0100 Am 15.11.2022 um 13:09 schrieb Öö Tiib: > overcommit is different. Overcommit results with OOM killer killing > processes, over-reserve results with processes attempting to commit > getting exceptions. You don't understood what I wrote. And I guess you aren't qualified to discuss the issue. |
Michael S <already5chosen@yahoo.com>: Nov 15 06:23AM -0800 On Tuesday, November 15, 2022 at 3:23:22 PM UTC+2, Bonita Montero wrote: > > getting exceptions. > You don't understood what I wrote. > And I guess you aren't qualified to discuss the issue. It seems to me that Öö Tiib is mostly correct. Except that I don't expect that processes are getting exceptions when attempting to commit. I expect that software entity that attempts to commit gets error code from the system call and then, in turn, raises an exception. But if said entity does not run in context of the process then result is the same. I don't know fine details and don't feel that they matter all that much. What *does* matter is that over-reserve is not the same as over-commit and that observed behavior does not prove over-commit. |
Bonita Montero <Bonita.Montero@gmail.com>: Nov 15 04:39PM +0100 Am 15.11.2022 um 15:23 schrieb Michael S: > It seems to me that Öö Tiib is mostly correct. > Except that I don't expect that processes are getting exceptions when > attempting to commit. ... For Linux this is always true with overcomitting enabled, for Windows it it true when one of the guard pages of the stack is hit and the system can't assign a physical page for that guard page. > I expect that software entity that attempts to commit gets error > code from the system call and then, in turn, raises an exception. When you touch a guard page there's no system call. You could simply walk down the whole stack until the last guard page on thread creation if you need reliable stack allocation. > What *does* matter is that over-reserve is not the same as over-commit > ... There's nothing like over-reserving, it's really over-comitting since the actual commit may fail if you touch the region of guard pages of the stack. There are usually two or three guard pages of the stack. I don't know what was Microsoft's decision to have a small amount of guard pages. I'd chosen that the whole stack region would be comittable on access except for the page at the bottom of the stack region. This f.e. would make an alloca() just a subtration from the current stack pointer. Actually there's a special function called which compares the final stack pointer after allocation by the lower stack limit which can be found in the thread information block (fs:[0x10] on x64) and walks the stack pages if appropriate. |
T <T@invalid.invalid>: Nov 14 04:25PM -0800 Hi All, Windows 11 22H2 Is there an (easy) way to find session ID of your running program? Many thanks, -T |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 14 04:29PM -0800 On 11/14/2022 4:25 PM, T wrote: > Windows 11 22H2 > Is there an (easy) way to find session ID of > your running program? PID? |
T <T@invalid.invalid>: Nov 14 05:23PM -0800 On 11/14/22 16:29, Chris M. Thomasson wrote: >> Is there an (easy) way to find session ID of >> your running program? > PID? Supposedly you can find it from your PID. Supposedly. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 14 05:40PM -0800 On 11/14/2022 5:23 PM, T wrote: >>> your running program? >> PID? > Supposedly you can find it from your PID. Supposedly. Are you experienced in Windows? |
Mike Terry <news.dead.person.stones@darjeeling.plus.com>: Nov 15 01:56AM On 15/11/2022 01:23, T wrote: >>> your running program? >> PID? > Supposedly you can find it from your PID. Supposedly. DWORD sessionId = 0; BOOL ok = ProcessIdToSessionId (GetCurrentProcessId(), &nSessionId); ... or it's returned by one of the WTS (Terminal Services) query APIs, but I think that requires terminal services to be running. (It gets much more info, but you only want the session ID so ProcessIdToSessionId is easy.) Also, I recall it's in the user's security token, so you might be interested by GetTokenInformation() - that's also more complicated, but if you need it to work on ancient Windows versions it might be what you need. :) For better answers probably best to post on a Windows newsgroup, as it's off topic here. (I just remembered this from my work before I retired...) Mike. |
T <T@invalid.invalid>: Nov 14 06:33PM -0800 On 11/14/22 17:40, Chris M. Thomasson wrote: >>> PID? >> Supposedly you can find it from your PID. Supposedly. > Are you experienced in Windows? If you mean programming for it, not so much. API all drive me nuts from Raku. I can't read C very well. |
T <T@invalid.invalid>: Nov 14 06:38PM -0800 On 11/14/22 17:56, Mike Terry wrote: > For better answers probably best to post on a Windows newsgroup, as it's > off topic here. (I just remembered this from my work before I retired...) > Mike. That call is only effective if you are not running as administrator from the Task Scheduler. It would be easy to port to Raku. This is the sample code I was given, that I thoroughly do not understand. Hmmmm.. Did not realize I even had to free memory or risk a memory leak. I just want my stinking session ID. I have everything else coded and working (from Raku). #define WIN32_LEAN_AND_MEAN #include <Windows.h> #include <WtsApi32.h> #pragma comment(lib, "wtsapi32") #include <stdio.h> #include <tchar.h> void Report(LPCTSTR pszFormat, ...) { TCHAR szMsg[512]; va_list pArg; va_start(pArg, pszFormat); _vsntprintf_s(szMsg, ARRAYSIZE(szMsg), ARRAYSIZE(szMsg) - 1, pszFormat, pArg); va_end(pArg); OutputDebugString(szMsg); } int _tmain() { TCHAR szTitle[]{ _T("Information") }; TCHAR szMsg[]{ _T("Hello From TaskMessageBox") }; DWORD dwResp{}; PWTS_SESSION_INFO pwsi{}; DWORD dwSession{}, dwCount{}; if (!WTSEnumerateSessions(WTS_CURRENT_SERVER, 0, 1, &pwsi, &dwCount)) { Report(_T("WTSEnumerateSessions failed with error code %d\n"), GetLastError()); return 0; } for (DWORD i = 0; i < dwCount; i++) { if (pwsi[i].State == WTSActive) { dwSession = pwsi[i].SessionId; break; } } WTSFreeMemory(pwsi); if (!dwSession) { Report(_T("No active sessions\n")); return 0; } BOOL fSuccess = WTSSendMessage(WTS_CURRENT_SERVER, dwSession, szTitle, ARRAYSIZE(szTitle) * sizeof(TCHAR), szMsg, ARRAYSIZE(szMsg) * sizeof(TCHAR), MB_ICONINFORMATION | MB_OK, 60, &dwResp, TRUE); if (fSuccess) Report(_T("WTSSendMessage succeeded, response was %d\n"), dwResp); else Report(_T("WTSSendMessage failed, error code was %d\n"), GetLastError()); return 0; } |
T <T@invalid.invalid>: Nov 14 08:08PM -0800 On 11/14/22 18:33, T wrote: > If you mean programming for it, not so much. API > all drive me nuts from Raku. I can't read C very > well. If you mean I.T. support, since its inception. I adored Windows for Workgroups 3.11 and NT 4.0. Not so much since then. But my customers are 95% on it, so I hold my nose. Raku is mostly a Linux thing. I am one of their beginner programmers. I have programed off and on for years, but Raku only for about four years now. I only get to program about once a month or so. I felt very good about the first program I got paid for about two years ago. I field Windows Raku questions, mostly about installation, every so often from the Raku mailing list, which should tell you how much they program for Windows. I officially support Windows, Mac, and Linux, but will work on anything, including DOS. I have one retiree who pays me to fix his home entertainment system everything he kicks out a wire or two with the vacuum cleaner. I make a whole $20 of him each time. |
Mike Terry <news.dead.person.stones@darjeeling.plus.com>: Nov 15 04:12AM On 15/11/2022 02:38, T wrote: > That call is only effective if you are not running > as administrator from the Task Scheduler. It would > be easy to port to Raku. You mean the ProcessIdToSessionId () API? That would work fine when started as system from the scheduler - but bear in mind that for such a process it's SessioId would probably be zero. Which kind of leads to the reason you wanted that session id... But rather than answer that here, I recommend you go to a Windows programming group. (Unless you have any C++ questions - those would be on topic for this newsgroup.) > Report(_T("WTSSendMessage failed, error code was %d\n"), GetLastError()); > return 0; > } That code looks quite typical for Windows - it enumerates the terminal sessions on the computer looking for the (first) "active" session. On Windows 10 that would generally be the user logged on via the physical console. (But in general there can be multiple user sessions active I think...) Then it sends a message box to that windows desktop. It's the sort of thing a system service might do - a normal user program would just call the MessageBox API! The Report routine sends messages to an attached debugger, which is not typical - most services would create system events, or (I prefer) write to a log file. If you're not familiar with Windows programming, naturally you'll struggle, and moreso if you're not C/C++ familiar! And if you choose interfaces based on COM it is just going to be a disaster, trust me, don't go there - there's too much background you'd have to suddenly pick up and become familiar with... (There's no COM in your sample code above.) Mike. |
T <T@invalid.invalid>: Nov 14 09:25PM -0800 On 11/14/22 20:12, Mike Terry wrote: > I recommend you go to a Windows programming group You have a recommendation for one? |
Bonita Montero <Bonita.Montero@gmail.com>: Nov 15 09:36AM +0100 I developed a little program that prints all sessions and their processes. To get all processes you need to run it unter Administrator privileges. #include <Windows.h> #include <TlHelp32.h> #include <iostream> #include <vector> #include <unordered_map> using namespace std; using XHANDLE = unique_ptr<void, decltype([]( void *h ) { h && h != INVALID_HANDLE_VALUE && CloseHandle( h ); })>; int main() { XHANDLE xhSnapshot( CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ); if( xhSnapshot.get() == INVALID_HANDLE_VALUE ) return EXIT_FAILURE; PROCESSENTRY32W pe; pe.dwSize = sizeof pe; if( !Process32FirstW( xhSnapshot.get(), &pe ) ) return EXIT_FAILURE; vector<PROCESSENTRY32W> processes; do processes.emplace_back( pe ), pe.dwSize = sizeof pe; while( Process32NextW( xhSnapshot.get(), &pe ) ); if( GetLastError() != ERROR_NO_MORE_FILES ) return EXIT_FAILURE; unordered_multimap<DWORD, PROCESSENTRY32W const *> sessionIdToProcesses; for( auto const &pe : processes ) { DWORD dwSessionId; if( !ProcessIdToSessionId( pe.th32ProcessID, &dwSessionId ) ) continue; sessionIdToProcesses.emplace( make_pair( dwSessionId, &pe ) ); } DWORD dwLastSession = -1; for( auto const &sessionAndProcess : sessionIdToProcesses ) { if( dwLastSession != sessionAndProcess.first ) dwLastSession = sessionAndProcess.first, cout << "SID " << dwLastSession << ": " << endl; auto const &pe = *sessionAndProcess.second; wcout << L"\t" << pe.th32ProcessID << L": \"" << pe.szExeFile << L"\"" << endl; } } |
T <T@invalid.invalid>: Nov 15 02:41AM -0800 On 11/15/22 00:36, Bonita Montero wrote: > << L"\"" << endl; > } > } Would you mind giving me the commands to compile, load, and run this? |
Bonita Montero <Bonita.Montero@gmail.com>: Nov 15 02:54PM +0100 Am 15.11.2022 um 11:41 schrieb T: > Would you mind giving me the commands to compile, > load, and run this? cl -Ox -std:c++20 xxx.cpp Or just create a Win32 console project with Visual Studio, copy that source to the main source file and enable C++20 in the project settings for both Debug- and Release-Builds. |
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Nov 14 05:36PM -0800 > which is using GetSystemTimePreciseAsFileTime() if compiled for > Windows 8 or higher and GetSystemTimeAsFileTime() otherwise:" > I used the gettimeofday function. Works well ! Be aware that POSIX says gettimeofday() is obsolescent, and recommends clock_gettime() instead. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */ |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment