LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2004, 11:41 PM   #1
kashifbilal
LQ Newbie
 
Registered: Apr 2004
Location: Pakistan
Distribution: Linux
Posts: 4

Rep: Reputation: 0
executing a program in new terminal?


Hi !!

Its my first question and mail on this forum .
Actually i m developing an application in which , when application runs , it forks 4 childs, i want to display a new terminal for each child process and execute a program using execl(), pleas tell me how can i execute a terminal(bash) from my application

thanks

kashif bilal
 
Old 04-14-2004, 12:00 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
First of all, welcome to LQ!

I'm not exactly sure what you're trying to do here. If you want to just start bash from a program than you can use one of the exec() family of functions to run /bin/bash.

However, if you're trying to open a new terminal window under X then you'd use one of the exec() family of functions to call your terminal application (i.e. xterm, konsole, etc.)

If you just want to run 4 different commands then opening a new shell (bash) is quite unnecessary. But if you want to open 4 new terminal windows and then have 1 command run in each then you can use popen() to run xterm/konsole/whatever and then send your command to the pointer that popen() returned. Something like this:

Code:
int main(void)
{
  FILE *term;
  int i;

  for(i = 0;i < 4;+=i)
  {
    term = popen("/usr/X11R6/bin/xterm", "w");
    fprintf(term, "mycommand\n");
    pclose(term);
  }
}
I think that would work anyway. I don't have access to a linux box at the moment

If I didn't answer your question just leave some more detail on what you're trying to accomplish.

Last edited by itsme86; 04-14-2004 at 12:01 AM.
 
Old 04-19-2004, 02:35 AM   #3
kashifbilal
LQ Newbie
 
Registered: Apr 2004
Location: Pakistan
Distribution: Linux
Posts: 4

Original Poster
Rep: Reputation: 0
Hi Its me !

Thanks for ur reply

U have said

However, if you're trying to open a new terminal window under X then you'd use one of the exec() family of functions to call your terminal application (i.e. xterm, konsole, etc.)

Actually I am developing a router software

My application first detects all interfaces ( NICs ) attached to system and then starts a packet capturing engine for all interaces.

So that to run a packet capturing engine , i want to run each one in different x window terminal. I think now u can understand what i want

thanks
kashif
 
Old 04-19-2004, 02:55 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Actually I can't understand why one would want to
develop a router that requires to be running within
an X environment...


Cheers,
Tink
 
Old 04-21-2004, 03:47 AM   #5
kashifbilal
LQ Newbie
 
Registered: Apr 2004
Location: Pakistan
Distribution: Linux
Posts: 4

Original Poster
Rep: Reputation: 0
Hi ! Actually i have not worked much in Linux,
we have used linuc GUI , and developed our application in C .

Now i want to run each process in different trminal , bcaz when i runall processes in one terminal , time is not given to all processes concurretly ,and one can se that which process is executing at this time and all other processes running in that terminal remains idle, so thats why i want torun each process in different terminal ,
just tyell methat how can i execute a new terminal from y program and run a seperate process in it
thanks

kashif
 
Old 04-21-2004, 08:36 AM   #6
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You can try this:

Code:
int main(void)
{
  FILE *fp[4];
  pid_t pids[4];
  int i;

  for(i = 0;i < 4;++i)
  {
    if((pids[i] = fork()))
    {
      fp[i] = popen("/bin/X11R6/xterm", "w");
      fprintf(fp[i], "command_to_run options\n");
    }
  }

  for(i = 0;i < 4;++i)
     waitpid(pids[i], NULL, 0);

  return 0;
}
I think that might work anyway
 
Old 04-21-2004, 02:28 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Well, as I said, I wouldn't want a networking product to
depend on X.

The linux way would be to spawn a sub-process and
redirect its output to a FIFO, for instance, and then
your processes run concurrently, and you can check
their output by reading their FIFOs.


Cheers,
Tink
 
Old 04-26-2004, 04:52 AM   #8
kashifbilal
LQ Newbie
 
Registered: Apr 2004
Location: Pakistan
Distribution: Linux
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks a lot for ur help and code brother

kashif
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing shell script in terminal directly with a double click kushalkoolwal Programming 15 11-26-2012 02:32 PM
Writing and executing a program Russb Linux - Software 1 07-25-2004 06:49 PM
Executing files in a terminal by default Vnet1 Linux - Newbie 2 03-24-2004 12:54 PM
Executing programs from a terminal window subzero0 Linux - General 0 09-26-2003 12:36 PM
Servlets executing a C program. webee Programming 1 02-04-2003 05:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration