On Thu, Nov 12, 2020 at 1:41 PM Cyrille Lefevre via Msys2-users
<msys2-users@lists.sourceforge.net> wrote:
Hi,
try using /proc/self/stat, see details from
https://man7.org/linux/man-pages/man5/proc.5.html
windows pid is got from /proc/self/winpid
Le 12/11/2020 à 09:36, Ameya Vikram Singh a écrit :
> Hi,
>
> I actually tried the following code:
> ////////////////////////////////////////////////////////////////
> #include <stdio.h>
> #include <unistd.h>
>
> int main()
> {
> pid_t pid = getpid();
>
> FILE *fi = fopen("/proc/self/stat", "r");
> if(fi)
> {
> printf("Able to open file\n");
> }
> else
> {
> printf("Unable to open file\n");
> }
>
> //system("ps aux");
> printf("PID: %llu\n", pid);
>
> return 0;
> }
> ////////////////////////////////////////////////////////////////
>
> I get the following print on the bash console for MinGW 64-bit:
> Unable to open file
> PID: 15072
>
> It seems in the MinGW context the UNIX layer emulation is disabled.
> Just wanted to know if there is an API something similar to:
> "cygwin_winpid_to_pid" to fetch the PID reflected by the ps command
for MinGW?
>
> If there is one how to link to it?
could you try this at the bash prompt level :
$ read pid rest < /proc/self/stat; echo $pid : $rest
680 : (bash) R 679 680 680 8912896 -1 0 22761 22761 0 0 101078 106296
101078 106296 20 0 0 0 2352723 9093120 1721 345
Regards,
Cyrille Lefevre
_______________________________________________
Msys2-users mailing list
Msys2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/msys2-users