Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!mit-eddie!uw-beaver!uw-entropy!dataio!shiloh!rwing!pat From: pat@rwing.UUCP (Pat Myrto {rwing}) Newsgroups: comp.unix.questions Subject: Re: Getting rid of controlling terminal Summary: Separating from terminal on the command line. Message-ID: <1064@rwing.UUCP> Date: 18 Feb 90 19:58:41 GMT References: <4018@rouge.usl.edu> Distribution: usa Organization: Very Little Organization, Seattle WA Lines: 62 In article <4018@rouge.usl.edu>, pcb@gator.cacs.usl.edu (Peter C. Bahrs) writes: > I hope this is the correct newsgroup, so many unix., but... > I want to run a job in the background and have it disconnect from > the associating terminal without hardcoding it. > i.e. when I do a ps -guax on Berkeley I want to see a ? in the tty column. The following little ditty is what I use for System V (also puts the program in the background). With some changes to use the syscall for setting a new process group under BSD, this should do what you have in mind. I'd be more specific, but I don't know BSD syscalls.... =========[ fsetpgrp.c - quick and dirty way to detach term assoc ]========== /* * Fsetpgrp - a simple command that places programs listed on * the command line in the background, and disassociates them * with the terminal (by setting a new process group). Note that * stdin, stdout, and stderr are NOT changed - if user wishes to * have those directed elsewhere, such as /dev/null, the user must * do this on the command line, as well. This is just meant to * be a quick and dirty convenience. */ #include main(argc,argv,envp) int argc; char *argv[], *envp[]; { int pid; if (argc < 2) { fprintf(stderr,"Usage: %s program [argv ... ]\n", argv[0]); exit(1); } pid = fork(); if(pid == -1) { fprintf(stderr, "fork failed.\n"); exit(1); } else if(pid > 0) { /* parent - just exit cleanly */ exit(0); } else { setpgrp(); /* child. setpgrp and exec program */ execvp(argv[1], &(argv[1])); perror(argv[0]); exit(1); } } ============================[ end ]================================= Hope this helps, or at least stimulates ideas for what you want. -- pat@rwing (Pat Myrto), Seattle, WA ...!uunet!pilchuck!rwing!pat ...!uw-beaver!uw-entropy!dataio!/ WISDOM: "Travelling unarmed is like boating without a life jacket"