{"id":16770,"date":"2022-10-22T03:13:06","date_gmt":"2022-10-21T21:43:06","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/"},"modified":"2022-10-22T03:13:06","modified_gmt":"2022-10-21T21:43:06","slug":"solved-segmentation-fault-filing-sleep-function","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/","title":{"rendered":"[Solved] segmentation fault filing sleep function"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-5211454\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"5211454\" data-parentid=\"5210735\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>The <code>else<\/code> branch of the <code>if(fsize==0)<\/code> conditional in <code>csvwrite()<\/code> does not <code>fclose(fe)<\/code>.  There is a limit on the number of files that can be opened by any one process at once; if you call this enough times, you&#8217;ll hit the limit, and the next <code>fopen()<\/code> will return <code>NULL<\/code> (and <code>errno<\/code> will be set to <code>EMFILE<\/code> &#8211; &#8220;Too many open files&#8221;).<\/p>\n<p>That may or may not be the problem, so here&#8217;s some more general advice:<\/p>\n<ol>\n<li>\n<p>Use a debugger.  If you don&#8217;t know how, you should learn!  For example:<\/p>\n<pre><code>$ cat test.c\n#include &lt;stdio.h&gt;\n\nint main(void)\n{\n    int a = 123, b, c;\n    int *p = &amp;a;\n    int *q = NULL;\n\n    b = *p;\n    c = *q;\n    printf(\"%d %d\\n\", b, c);\n    return 0;\n}\n$ gcc -Wall -o test test.c\n$ .\/test\nSegmentation fault\n$\n<\/code><\/pre>\n<p>Not very helpful.  But compile with <code>-g<\/code> and run it with <code>gdb<\/code>:<\/p>\n<\/p>\n<pre>$ gcc <b>-g<\/b> -Wall -o test test.c\n$ <b>gdb .\/test<\/b>\nGNU gdb 6.8-debian\nCopyright (C) 2008 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later &lt;http:\/\/gnu.org\/licenses\/gpl.html&gt;\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\nThis GDB was configured as \"i486-linux-gnu\"...\n(gdb) run\nStarting program: \/tmp\/test \n<\/pre>\n<p>&#8230;and it will reveal the line where it fails:<\/p>\n<pre>\nProgram received signal SIGSEGV, Segmentation fault.\n<b>0x080483d4 in main () at test.c:10\n10        c = *q;<\/b>\n(gdb) quit\nThe program is running.  Exit anyway? (y or n) y\n$ \n<\/pre>\n<\/li>\n<li>\n<p>Compile with warnings enabled (as I have done above with the <code>-Wall<\/code> flag).  The compiler is capable of spotting quite a lot of silly things, but you have to ask it.<\/p>\n<\/li>\n<li>\n<p>Try indenting the code sensibly.  Readable code is easier to debug.<\/p>\n<\/li>\n<li>\n<p>Remember to check return values.  <code>fopen()<\/code> in particular can fail for any number of reasons which are unrelated to your program.<\/p>\n<\/li>\n<li>\n<p>Don&#8217;t write vast amounts of practically identical code.  If you have to do the same job more than once, consider factoring it out into a separate function.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved segmentation fault filing sleep function <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] The else branch of the if(fsize==0) conditional in csvwrite() does not fclose(fe). There is a limit on the number of files that can be opened by any one process at once; if you call this enough times, you&#8217;ll hit the limit, and the next fopen() will return NULL (and errno will be set to &#8230; <a title=\"[Solved] segmentation fault filing sleep function\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\" aria-label=\"More on [Solved] segmentation fault filing sleep function\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,575,424],"class_list":["post-16770","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-file-io","tag-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] segmentation fault filing sleep function - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] segmentation fault filing sleep function - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] The else branch of the if(fsize==0) conditional in csvwrite() does not fclose(fe). There is a limit on the number of files that can be opened by any one process at once; if you call this enough times, you&#8217;ll hit the limit, and the next fopen() will return NULL (and errno will be set to ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-21T21:43:06+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] segmentation fault filing sleep function\",\"datePublished\":\"2022-10-21T21:43:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\"},\"wordCount\":204,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"file-io\",\"linux\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\",\"name\":\"[Solved] segmentation fault filing sleep function - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-21T21:43:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] segmentation fault filing sleep function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] segmentation fault filing sleep function - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] segmentation fault filing sleep function - JassWeb","og_description":"[ad_1] The else branch of the if(fsize==0) conditional in csvwrite() does not fclose(fe). There is a limit on the number of files that can be opened by any one process at once; if you call this enough times, you&#8217;ll hit the limit, and the next fopen() will return NULL (and errno will be set to ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/","og_site_name":"JassWeb","article_published_time":"2022-10-21T21:43:06+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] segmentation fault filing sleep function","datePublished":"2022-10-21T21:43:06+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/"},"wordCount":204,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","file-io","linux"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/","url":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/","name":"[Solved] segmentation fault filing sleep function - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-21T21:43:06+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-segmentation-fault-filing-sleep-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] segmentation fault filing sleep function"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=16770"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16770\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=16770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=16770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=16770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}