![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems installing a program through Terminal in Mac OS X | Sixmax | UNIX for Dummies Questions & Answers | 1 | 05-12-2008 12:52 PM |
| Problems installing a program in Terminal | Sixmax | Shell Programming and Scripting | 4 | 04-10-2008 01:05 PM |
| Control process from different terminal (over SSH) | rakeshou | UNIX for Advanced & Expert Users | 3 | 12-19-2007 08:48 PM |
| Terminal control from rsh | zam | Shell Programming and Scripting | 2 | 09-22-2005 08:07 PM |
| Terminal Control Database Entry | kayode | SCO | 2 | 10-23-2003 06:58 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
terminal device control through a C/C++ program
Hi,
I want to fork a new process from a daemon that needs terminal attachment to some ttyN or pts/N device. Here is the code #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <string.h> int main(int argc, char **args) { char *con = args[1]; printf("\nStart demonizing ...\n"); int i = fork(); if (i == 0) { close (0); close (1); close (2); setsid(); int j = fork(); if (j == 0) { setsid(); //int in = open(con, O_RDWR); int in = open(con, O_RDONLY); int ou = open(con, O_WRONLY); dup2(in, fileno(stdin)); dup2(ou, fileno(stdout)); dup2(ou, fileno(stderr)); printf("\n input :"); stdin = fdopen(0, "r"); stdout = fdopen(1, "w"); stderr = fdopen(2, "w"); char tmp[100]; strcpy(tmp, ""); //gets(tmp); fread(tmp, sizeof(tmp), 1, stdin); printf("\n output : %s\n", tmp); } exit(0); } } The program takes a single command line argument - the name of the terminal device special file, in my case that will be /dev/"pts/1". The problem is that, the inner most spawned child does the output on the pts/1 terminal successfully, but it fails to take input from it. Anyone can help here. Last edited by ku@ntum; 05-23-2007 at 08:28 AM.. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|