public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* debugging rlimit
@ 2013-09-25 21:45 Eric Blake
  2013-10-14 13:22 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Blake @ 2013-09-25 21:45 UTC (permalink / raw)
  To: cygwin-developers

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

How am I supposed to debug code related to rlimit, when it appears that
gdb/strace resets it to default values?

$ cat foo.c
#include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
int main(void) {
  struct rlimit r;
  if (!getrlimit(RLIMIT_NOFILE, &r))
    printf("%ld %ld\n", r.rlim_cur, r.rlim_max);
  return 0;
}
$ ./foo
256 3200
$ (ulimit -n 1000; ./foo)
1000 3200
$ (ulimit -n 1000; strace -o /dev/null ./foo)
256 3200

Since rlimit is intertwined with getdtablesize(), I'd like to be able to
debug a process that starts with a different limit than normal.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: debugging rlimit
  2013-09-25 21:45 debugging rlimit Eric Blake
@ 2013-10-14 13:22 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2013-10-14 13:22 UTC (permalink / raw)
  To: cygwin-developers

[-- Attachment #1: Type: text/plain, Size: 1206 bytes --]

On Sep 25 15:45, Eric Blake wrote:
> How am I supposed to debug code related to rlimit, when it appears that
> gdb/strace resets it to default values?
> 
> $ cat foo.c
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/resource.h>
> int main(void) {
>   struct rlimit r;
>   if (!getrlimit(RLIMIT_NOFILE, &r))
>     printf("%ld %ld\n", r.rlim_cur, r.rlim_max);
>   return 0;
> }
> $ ./foo
> 256 3200
> $ (ulimit -n 1000; ./foo)
> 1000 3200
> $ (ulimit -n 1000; strace -o /dev/null ./foo)
> 256 3200
> 
> Since rlimit is intertwined with getdtablesize(), I'd like to be able to
> debug a process that starts with a different limit than normal.

You can workaround this problem by attaching to the process after it
started.  In the dumbest possible way, you can add something like this
to main:

  1  printf ("PID %u, waiting...\n", getpid ());
  2  sleep (10);
  3  printf ("Here I am\n");

Attach to the process during the sleep period, and, in GDB, set a
breakpoint to line 3 and continue execution.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-14 13:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-25 21:45 debugging rlimit Eric Blake
2013-10-14 13:22 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).