C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 5th, 2003, 01:52 AM
OB_redemption's Avatar
OB_redemption OB_redemption is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 32 OB_redemption User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
fork a process with a different terminal?

Is it possible, after forking a process, to have that process run in a different terminal?

The idea is to have a client and a server terminal, each with it's own stdin, stdout and stderr.

Reply With Quote
  #2  
Old February 5th, 2003, 01:39 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
Do you need the process to do it programmatically, or is it ok to use the command line to redirect the output. I mean, can you do something like this instead:

nohup /path/to/program > /dev/tty2 &

This way your program does not need to fork() at all (I'm assuming you're using fork() to put the process in the background). Actually, I used the same fork() trick on some of my code before discovering that this may actually be a Bad Thing. Incidentally, one more thing I discovered is that when I fork() a process into a background, some of my threading code didn't work on FreeBSD, but worked on Linux just fine. Removing the fork() made it work on both systems!

Hope this helps!

Reply With Quote
  #3  
Old February 5th, 2003, 02:19 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
you can close() the three file descriptors for stdin, stdout and stderr (0,1,2) and re- open() them on a new terminal (eg. /dev/tty8).

Scorpions4ever: very interesting URL. i´m off reading now...
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #4  
Old February 6th, 2003, 02:01 AM
OB_redemption's Avatar
OB_redemption OB_redemption is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 32 OB_redemption User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Thanks for the replies guys!

Just to fix a few mistakes in my initial query. I mentioned fork()ing because I'd figured it would be similar to creating a new thread. I'm actually using an implementation of Linda (tuple-space) which uses POSIX threads for internal synchronization (sorry I didn't mention that it uses threads and not a separate process, as I wasn't thinking that it'd matter).

Basically, I'm spawning off a new thread (via the Linda implementation's spawn() functon) which would be the client thread of execution. There can be more than 1 client. And the thing is I need each client to read/write from a different 'window' or terminal from the server thread.

Scorpions4ever: I don't _think_ using nohup would work because it's actually a thread that I'm trying to attach to a terminal, not a program. Is that right?

M.Hirsch: How do I accomplish that? Would it work for a thread? I only know how to open() , dup2() fds in the case of processes but for threads it would be different wouldn't it?

Thanks again!

Reply With Quote
  #5  
Old February 6th, 2003, 10:11 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
as threads run in one process, you only need to close the handles in your main() function - unless this "Linda" uses processes to emulate threads where i could not help you any further...

Anyway, afaik you should use multiple processes in linux as unix is afaik much more effective if using processes instead of threads. Threads are for windows programming. But this knowledge might be a little outdated...

But i am not sure if multiple threads can be connected to different terminals. you could just open() a new descriptor to write to another terminal though... (probably easier to use: fopen() the tty device and write to it as if it was a file)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > fork a process with a different terminal?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway