GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Embed Notice

HTML Code

Corresponding Notice

  1. Embed this notice
    Jann Horn (jann@infosec.exchange)'s status on Tuesday, 19-Aug-2025 17:38:42 JSTJann HornJann Horn

    Linux kernel quiz: Why is this program so slow and takes around 50ms to run?
    What line do you have to add to make it run in ~3ms instead without interfering with what this program does?

    user@debian12:~/test$ cat > slow.c
    #include <pthread.h>
    #include <unistd.h>
    #include <err.h>
    #include <sys/socket.h>

    static void open_sockets(void) {
    for (int i=0; i<256; i++) {
    int sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1)
    err(1, "socket");
    }
    }

    static void *thread_fn(void *dummy) {
    open_sockets();
    return NULL;
    }

    int main(void) {
    pthread_t thread;
    if (pthread_create(&thread, NULL, thread_fn, NULL))
    errx(1, "pthread_create");
    open_sockets();
    if (pthread_join(thread, NULL))
    errx(1, "pthread_join");
    return 0;
    }
    user@debian12:~/test$ gcc -O2 -o slow slow.c -Wall
    user@debian12:~/test$ time ./slow

    real 0m0.041s
    user 0m0.003s
    sys 0m0.000s
    user@debian12:~/test$ time ./slow

    real 0m0.053s
    user 0m0.003s
    sys 0m0.000s
    user@debian12:~/test$
    In conversationabout a month ago from infosec.exchangepermalink
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.