c++ - How do you clone() in linux inside a class and namespace? -


i'm taking intro operating systems course , we're use clone() call in linux create threads , stuff them. seem having trouble using clone() @ all.

i've structured code single class (called homework) in namespace class (course). may problem first time i've used namespace keyword. i'm trying use things become more experienced if have dumb mistake, it.

i found articles on web didn't much. i've read man page guess i'm not experienced enough understand problem is. 1 day! assistance :)

i want have method catch clones inside class:

// -- header -- //   namespace _course_ {       class _homework_ {                  ...           int threadcatch(void *);                  ...      };   }  // -- source -- //   namespace _course_ {      void _homework_::threadtest(void) {                ...        // web article        void **childstack;        childstack = ( void **) malloc(kilobyte);        clone(threadcatch, childstack, clone_vm | clone_files, null);                ...     }      int _homework_::threadcatch(void * ){       cout << getpid() << " cloned." << endl;         exit(0);     } } 

is have. i've tried different ways (taking catcher out of class, namespace). it's compiled twice when try recompiled after make clean tells me function (threadcreate) declared in multiple locations. because of these weird errors i'm sure i'm doing wrong , instead of hack @ i'll take opinions. should do, or should read next? thanks!

define catch function static class function.

static int threadcatch(void *); 

also (and don't need this, in case, i'll here) might need use scope resolution operators send clone(). don't think so, since you're using inside of homework class already. in case, might you.

clone(homework::threadcatch, childstack, clone_vm | clone_files, null); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -