Note that there are some explanatory texts on larger screens.

plurals
  1. POUnsigned Long does not contain valid value
    primarykey
    data
    text
    <p>My question is something I find very weird. In fact, I'm listing all the child processes of a given process.</p> <p>For this, I use : <a href="https://stackoverflow.com/questions/1009552/how-to-find-all-child-processes">How to find all child processes?</a> and RC's answer.</p> <p>But, I need an exit with unsigned long. And the solution give some string based on a <code>char[]</code></p> <p>If I want to get <code>unsigned long</code>, I need to modify the code to get only numeric value. The other case will not be correct.</p> <p>So I've put the <code>char</code> as <code>unsigned long</code>. Then, the <code>scanf</code> with <code>%ld</code> tags.</p> <p>But I'm getting crap ...</p> <p>Why does that not work ?</p> <p>EDIT : Code :</p> <pre><code>const char *name = "top"; char command[100]; unsigned long parentID; unsigned long processID; strcpy(command, "ps -C "); strcat(command, name); strcat(command, " --format '%P %p'"); FILE *fp = popen(command, "r"); if (fp == NULL) fprintf(stderr, "Error in reading PID child processes information !\n"); while(fscanf(fp, "%lu %lu", parentID, processID) != EOF) { printf("PID : %lu Parent : %lu \n", processID, parentID); } return processID; </code></pre> <p>With, <code>%s</code> and <code>char[256]</code>, this work !</p> <p>EDIT : Toughts</p> <p>I was thinking of two ways to do this:</p> <ul> <li>First, using <code>unsigned long</code> instead of <code>char[]</code>.</li> <li>Second, convert <code>char[]</code> to <code>unsigned long</code> after reading the file. However, I'd need to read it line by line. Is it possible with <code>popen</code> ?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload