本文整理汇总了C++中rfork函数的典型用法代码示例。如果您正苦于以下问题:C++ rfork函数的具体用法?C++ rfork怎么用?C++ rfork使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rfork函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: vtAttach
void
vtAttach(void)
{
int pid;
Thread *p;
static int init;
static Lock lk;
lock(&lk);
if(!init) {
rfork(RFREND);
vtThreadInit();
init = 1;
}
unlock(&lk);
pid = getpid();
p = *vtRock;
if(p != nil && p->pid == pid) {
p->ref++;
return;
}
p = vtMemAllocZ(sizeof(Thread));
p->ref = 1;
p->pid = pid;
*vtRock = p;
}
开发者ID:npe9,项目名称:harvey,代码行数:27,代码来源:plan9-thread.c
示例2: execproc
void
execproc(void *v)
{
Channel *sync;
Exec *e;
int p[2], q[2];
char *cmd;
threadsetname("execproc");
e = v;
p[0] = e->p[0];
p[1] = e->p[1];
q[0] = e->q[0];
q[1] = e->q[1];
cmd = e->cmd;
sync = e->sync;
rfork(RFFDG);
free(e);
dup(p[0], 0);
close(p[0]);
close(p[1]);
if(q[0]){
dup(q[1], 1);
close(q[0]);
close(q[1]);
}
if(!procstderr)
close(2);
procexecl(sync, "/bin/rc", "rc", "-c", cmd, 0);
error("can't exec");
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:31,代码来源:util.c
示例3: notifyproc
/*
* process to notify other servers of changes
* (also reads in new databases)
*/
void
notifyproc(void)
{
Request req;
switch(rfork(RFPROC|RFNOTEG|RFMEM|RFNOWAIT)){
case -1:
return;
case 0:
break;
default:
return;
}
procsetname("notify slaves");
memset(&req, 0, sizeof req);
req.isslave = 1; /* don't fork off subprocesses */
for(;;){
getactivity(&req, 0);
notify_areas(owned, &req);
putactivity(0);
sleep(60*1000);
}
}
开发者ID:99years,项目名称:plan9,代码行数:29,代码来源:dnnotify.c
示例4: main
void
main(int argc, char **argv)
{
int i;
ARGBEGIN{
}ARGEND;
if(argc == 0){
fprint(2, "usage: %s portrange\n", argv0);
exits("usage");
}
switch(rfork(RFREND|RFNOTEG|RFFDG|RFPROC|RFNAMEG)){
case 0:
close(0);
close(1);
break;
case -1:
abort(); /* "fork failed\n" */;
default:
_exits(0);
}
for(i = 0; i < argc; i++)
hogrange(argv[i]);
close(2);
for(;;)
sleep(10000);
}
开发者ID:99years,项目名称:plan9,代码行数:31,代码来源:hogports.c
示例5: fromstdin
void
fromstdin(Conn *c)
{
int n;
char buf[1024];
int pid;
int eofs;
switch(pid = rfork(RFMEM|RFPROC|RFNOWAIT)){
case -1:
error("fork: %r");
case 0:
break;
default:
atexitkill(pid);
return;
}
atexit(atexitkiller);
if(interactive)
rawon();
notify(cookedcatchint);
eofs = 0;
for(;;){
n = read(0, buf, sizeof(buf));
if(n < 0){
if(wasintr()){
if(!raw){
buf[0] = 0x7f;
n = 1;
}else
continue;
}else
break;
}
if(n == 0){
if(!c->interactive || ++eofs > 32)
break;
}else
eofs = 0;
if(interactive && usemenu && n && memchr(buf, 0x1c, n)) {
if(menu(c)=='q'){
sendwritemsg(c, "", 0);
exits("quit");
}
continue;
}
if(!raw && n==0){
buf[0] = 0x4;
n = 1;
}
sendwritemsg(c, buf, n);
}
sendwritemsg(c, "", 0);
if(n >= 0) /* weren't hung up upon? */
atexitdont(atexitkiller);
exits(nil);
}
开发者ID:aahud,项目名称:harvey,代码行数:60,代码来源:ssh1.c
示例6: execproc
static void
execproc(void *a)
{
int i, fd;
Client *c;
char tmp[32];
c = a;
snprint(tmp, sizeof tmp, "execproc%d", c->num);
threadsetname(tmp);
if(pipe(c->fd) < 0){
rerrstr(c->err, sizeof c->err);
sendul(c->execpid, -1);
return;
}
rfork(RFFDG);
fd = c->fd[1];
close(c->fd[0]);
dup(fd, 0);
dup(fd, 1);
for(i=3; i<100; i++) /* should do better */
close(i);
strcpy(c->err, "exec failed");
procexecl(c->execpid, "/bin/rc", "rc", "-c", c->cmd, nil);
}
开发者ID:vrthra,项目名称:9front-tmp,代码行数:25,代码来源:client.c
示例7: spawnWaiter
void
spawnWaiter(Lock *l)
{
int pid;
int64_t start;
switch((pid = rfork(RFMEM|RFPROC|RFNOWAIT)))
{
case 0:
/* wait for the alwaysLocked to be locked by the main process */
qlock(&rl);
while(resInWaiter == 0xff)
rsleep(&rStart);
start = nsec();
resInWaiter = lockt(l, 6000);
elapsedInWaiter = (nsec() - start) / (1000 * 1000);
if(verbose)
print("lockt returned %d, elapsed = %d ms\n", resInWaiter, elapsedInWaiter);
rwakeup(&rCompleted);
qunlock(&rl);
exits(0);
break;
case -1:
print("spawnWaiter: %r\n");
exits("rfork fails");
break;
default:
if(verbose)
print("spawn waiter %d\n", pid);
break;
}
}
开发者ID:aahud,项目名称:harvey,代码行数:35,代码来源:lockt.c
示例8: main
void
main(int argc, char **argv)
{
Mainarg *a;
Proc *p;
rfork(RFREND);
mainp = &p;
if(setjmp(_mainjmp))
_schedinit(p);
//_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
_systhreadinit();
_qlockinit(_threadrendezvous);
_sysfatal = _threadsysfatal;
_dial = _threaddial;
__assert = _threadassert;
notify(_threadnote);
if(mainstacksize == 0)
mainstacksize = 8*1024;
a = _threadmalloc(sizeof *a, 1);
a->argc = argc;
a->argv = argv;
p = _newproc(mainlauncher, a, mainstacksize, "threadmain", 0, 0);
_schedinit(p);
abort(); /* not reached */
}
开发者ID:npe9,项目名称:harvey,代码行数:29,代码来源:main.c
示例9: start_host
static int
start_host(void)
{
int fd;
cs = consctl();
switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
case 0:
fd = open("/dev/cons", OREAD);
dup(fd,0);
if(fd != 0)
close(fd);
fd = open("/dev/cons", OWRITE);
dup(fd,1);
dup(fd,2);
if(fd != 1 && fd !=2)
close(fd);
execl("/bin/rc","rcX",nil);
fprint(2,"failed to start up rc\n");
_exits("rc");
case -1:
fprint(2,"rc startup: fork error\n");
_exits("rc_fork");
}
return open("/mnt/cons/data", ORDWR);
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:28,代码来源:event.c
示例10: blockread
int
blockread(int in, char *first, int nfirst)
{
int p[2], out, n, rv;
char blk[512];
if(pipe(p) < 0)
sysfatal("pipe: %r");
rv = p[0];
out = p[1];
switch(rfork(RFPROC|RFNOTEG|RFFDG)){
case -1:
sysfatal("fork: %r");
case 0:
close(rv);
break;
default:
close(in);
close(out);
return rv;
}
write(out, first, nfirst);
while((n=read(in, blk, sizeof blk)) > 0){
if(write(out, blk, n) != n)
break;
if(n == sizeof(blk) && memcmp(zero, blk, n) == n)
break;
}
_exits(0);
return -1;
}
开发者ID:aahud,项目名称:harvey,代码行数:33,代码来源:mkext.c
示例11: newwindow
/* Connect us to new window, if possible */
int
newwindow(char *str)
{
int fd;
char *wsys;
char buf[256];
wsys = getenv("wsys");
if(wsys == nil)
return -1;
fd = open(wsys, ORDWR);
if(fd < 0){
free(wsys);
return -1;
}
rfork(RFNAMEG);
unmount(wsys, "/dev"); /* drop reference to old window */
free(wsys);
if(str)
snprint(buf, sizeof buf, "new %s", str);
else
strcpy(buf, "new");
if(mount(fd, -1, "/mnt/wsys", MREPL, buf) < 0)
return mount(fd, -1, "/dev", MBEFORE, buf);
return bind("/mnt/wsys", "/dev", MBEFORE);
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:27,代码来源:newwindow.c
示例12: main
// main takes care of OS-specific startup and dispatches to xmain.
void
main(int argc, char **argv)
{
Buf b;
setvbuf(stdout, nil, _IOLBF, BUFSIZ);
setvbuf(stderr, nil, _IOLBF, BUFSIZ);
binit(&b);
rfork(RFENVG);
slash = "/";
gohostos = "plan9";
xgetenv(&b, "objtype");
if(b.len == 0)
fatal("$objtype is unset");
gohostarch = btake(&b);
xgetenv(&b, "GOBIN");
if(b.len == 0){
bpathf(&b, "/%s/bin", gohostarch);
xsetenv("GOBIN", bstr(&b));
}
srand(time(0)+getpid());
init();
xmain(argc, argv);
bfree(&b);
exits(nil);
}
开发者ID:icattlecoder,项目名称:go,代码行数:34,代码来源:plan9.c
示例13: copyout
void
copyout(Conn *c, int fd, int mtype)
{
char buf[8192];
int n, max, pid;
Msg *m;
max = sizeof buf;
if(max > maxmsg - 32) /* 32 is an overestimate of packet overhead */
max = maxmsg - 32;
if(max <= 0)
sysfatal("maximum message size too small");
switch(pid = rfork(RFPROC|RFMEM|RFNOWAIT)){
case -1:
sysfatal("fork: %r");
case 0:
break;
default:
atexitkill(pid);
return;
}
while((n = read(fd, buf, max)) > 0){
m = allocmsg(c, mtype, 4+n);
putlong(m, n);
putbytes(m, buf, n);
sendmsg(m);
}
exits(nil);
}
开发者ID:aahud,项目名称:harvey,代码行数:31,代码来源:sshserve.c
示例14: main
void
main(int, char **)
{
int ctl;
wdog = open("#w/wdctl", ORDWR);
if (wdog < 0)
sysfatal("open #w/wdctl: %r");
switch(rfork(RFPROC|RFNOWAIT|RFFDG)){
case 0:
break;
default:
exits(0);
}
ctl = procctl(getpid());
fprint(ctl, "pri 18");
close(ctl);
if (fprint(wdog, "enable") < 0)
sysfatal("write #w/wdctl enable: %r");
for(;;){
sleep(300); /* allows 4.2GHz CPU, with some slop */
seek(wdog, 0, 0);
if (fprint(wdog, "restart") < 0)
sysfatal("write #w/wdctl restart: %r");
}
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:29,代码来源:watchdog.c
示例15: eforkslave
static int
eforkslave(ulong key)
{
int i, pid;
for(i=0; i<MAXSLAVE; i++)
if((key & ~(1<<i)) == 0 && eslave[i].pid == 0){
if(nslave <= i)
nslave = i + 1;
/*
* share the file descriptors so the last child
* out closes all connections to the window server.
*/
switch(pid = rfork(RFPROC)){
case 0:
return MAXSLAVE+i;
case -1:
fprint(2, "events: fork error\n");
exits("fork");
}
eslave[i].pid = pid;
eslave[i].head = eslave[i].tail = 0;
return i;
}
drawerror(display, "events: bad slave assignment");
return 0;
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:27,代码来源:event.c
示例16: keeplockalive
/*
* like trylock, but we've already got the lock on fd,
* and don't want an L. lock file.
*/
static Mlock *
keeplockalive(char *path, int fd)
{
char buf[1];
Mlock *l;
l = malloc(sizeof(Mlock));
if(l == 0)
return 0;
l->fd = fd;
l->name = s_new();
s_append(l->name, path);
/* fork process to keep lock alive until sysunlock(l) */
switch(l->pid = rfork(RFPROC)){
default:
break;
case 0:
fd = l->fd;
for(;;){
sleep(1000*60);
if(pread(fd, buf, 1, 0) < 0)
break;
}
_exits(0);
}
return l;
}
开发者ID:npe9,项目名称:harvey,代码行数:32,代码来源:runq.c
示例17: _schedexecwait
void
_schedexecwait(void)
{
int pid;
Channel *c;
Proc *p;
Thread *t;
Waitmsg *w;
p = _threadgetproc();
t = p->thread;
pid = t->ret;
_threaddebug(DBGEXEC, "_schedexecwait %d", t->ret);
rfork(RFCFDG);
for(;;){
w = wait();
if(w == nil)
break;
if(w->pid == pid)
break;
free(w);
}
if(w != nil){
if((c = _threadwaitchan) != nil)
sendp(c, w);
else
free(w);
}
threadexits("procexec");
}
开发者ID:npe9,项目名称:harvey,代码行数:31,代码来源:main.c
示例18: install
/*
* Stream the three temp files to an archive
*/
void
install(char *arname, Arfile *astart, Arfile *amiddle, Arfile *aend, int createflag)
{
int fd;
if(allobj && dupfound) {
fprint(2, "%s not changed\n", arname);
return;
}
/* leave note group behind when copying back; i.e. sidestep interrupts */
rfork(RFNOTEG);
if(createflag)
fprint(2, "ar: creating %s\n", arname);
fd = arcreate(arname);
if(allobj)
rl(fd);
if (astart) {
arstream(fd, astart);
arfree(astart);
}
if (amiddle) {
arstream(fd, amiddle);
arfree(amiddle);
}
if (aend) {
arstream(fd, aend);
arfree(aend);
}
close(fd);
}
开发者ID:CoryXie,项目名称:nix-os,代码行数:36,代码来源:ar.c
示例19: runcmd
void
runcmd(int reqfd, int datafd, char *svc, char *cmd, char *arg1, char *arg2)
{
char *p;
int fd, cmdpid, child;
cmdpid = rfork(RFPROC|RFMEM|RFNOTEG|RFFDG|RFENVG);
switch (cmdpid) {
case -1:
syslog(0, "ssh", "fork failed: %r");
exits("fork");
case 0:
if (restdir == nil) {
p = smprint("/usr/%s", uname);
if (p && access(p, AREAD) == 0 && chdir(p) < 0) {
syslog(0, "ssh", "can't chdir(%s): %r", p);
exits("can't chdir");
}
free(p);
}
p = strrchr(cmd, '/');
if (p)
++p;
else
p = cmd;
dup(datafd, 0);
dup(datafd, 1);
dup(datafd, 2);
close(datafd);
putenv("service", svc);
fprint(errfd, "starting %s\n", cmd);
execl(cmd, p, arg1, arg2, nil);
syslog(0, "ssh", "cannot exec %s: %r", cmd);
exits("exec");
default:
close(datafd);
fprint(errfd, "waiting for child %d\n", cmdpid);
while ((child = waitpid()) != cmdpid && child != -1)
fprint(errfd, "child %d passed\n", child);
if (child == -1)
fprint(errfd, "wait failed: %r\n");
syslog(0, "ssh", "server closing ssh session for %s", uname);
fprint(errfd, "closing connection\n");
fprint(reqfd, "close");
p = smprint("/proc/%d/notepg", toppid);
if (p) {
fd = open(p, OWRITE);
fprint(fd, "interrupt");
close(fd);
}
exits(nil);
}
}
开发者ID:99years,项目名称:plan9,代码行数:56,代码来源:sshsession.c
示例20: threadmain
void
threadmain(int argc, char *argv[])
{
static Args args;
args.argc = argc;
args.argv = argv;
rfork(RFNAMEG);
proccreate(realmain, &args, 16*1024);
}
开发者ID:99years,项目名称:plan9,代码行数:10,代码来源:depend.c
注:本文中的rfork函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论