cloning.c

来自「多线程库」· C语言 代码 · 共 60 行

C
60
字号
/***************************************************************************                          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;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?