cloning.c
上传用户:shtangtang
上传日期:2007-01-04
资源大小:167k
文件大小:2k
- /***************************************************************************
- cloning.c - description
- -------------------
- begin : Mon Jan 31 2000
- copyright : (C) 2000 by 豶n E. Hansen
- email : oe.hansen@gamma.telenordia.se
- ***************************************************************************/
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
- #include <stdarg.h>
- #include <termio.h>
- #include <sched.h>
- #include <unistd.h>
- #include <sys/file.h>
- #include <sys/stat.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/resource.h>
- #include <malloc.h>
- #include <memory.h>
- #include <string.h>
- #include <pthread.h>
- #include <langinfo.h>
- #include <libintl.h>
- #include <syslog.h>
- #include <ctype.h>
- #include "cloning.h"
- do_clone(int (*_fn)(void *), void *_arg, void **_sp)
- {
- char *sp;
- int pid;
- if (*_sp)
- sp = (char *)*_sp;
- else
- sp = malloc(4*PAGE_SIZE);
- if (sp == NULL)
- return -2;
- pid = __clone(_fn, sp+(4*PAGE_SIZE), CLONE_VM|CLONE_FS|CLONE_FILES, _arg);
- if (pid < 0) {
- if (*_sp == NULL)
- free(sp);
- sp = NULL;
- }
- *_sp = (void *)sp;
- return pid;
- }