compiling c++ code in another shell?

N

neo2012

Guest
Hi all;
i want to compile a code in another shell('because that code contains an infinite loop and i want to pause and kill it by a shell) so i need a command to run code in another shell?
Thanks in advance
 


I don't understand what you mean....
Surely you just open one terminal and navigate to the location of the source code/makefile for your program and compile your program from there.
You can open another terminal and navigate to the same location and run the executable that you compiled in the other shell. I don't see where the problem is!

If you use a terminal emulator like Terminator, you can split a single terminal window horizontally and vertically any number of times using built-in keybinds to create multiple terminal sessions in a single window. If that's any help?!

WRT running programs in the terminal:
If you have a program which is running in the terminal as a foreground process and it's stopping you from doing things on the command line whilst it runs, you can use the ctrl-z key combo to stop/pause it. NOTE: This does not kill the program/process, it merely stops/pauses it.

After stopping/pausing a program using ctrl-z, you can resume it in the foreground using the fg command. Or if you have multiple processes stopped, you can use the command:
Code:
fg {pid}
to start a particular process running again - Where {pid} is the process ID of the process. NOTE: the PID will always be a number.

Alternatively if you want it to restart a stopped program to run in the background, you can use the bg command. Again, bg can take a process ID as a parameter if you have multiple processes that are stopped.

To list all of the processes that are associated with the current terminal, you can use the command:
Code:
jobs -l

And of course if you want to stop a program/process running altogether, you can use the kill command.

Is that any help to you?

Otherwise, can you explain more clearly what you are after because I am out of ideas!
 
Last edited:
Thanks for your reply, but i know how to pause and stop a program, my problem is i want a command to run a program in another shell, i.e by writing " ./test " ( test is a executable file ) test would be ran in same shell but i want a command to open a duplicate shell and run it in that( not opening the second shell by clicking) i wish i've made it clear enough . again thanks for your reply.
 
You don't need just another shell, you need a new instance of a terminal program (or a new tab in a running instance if that's supported).

So, to accomplish what I think you want, you'd do:

konsole -e test

always assuming that test is the name of your binary.

When your binary exits, the terminal will go away, too.
 
Ah, I see! So you want a command that will spawn a new terminal window and execute your program.
The exact way to do it would depend on which terminal you are using. Referring back to this thread from a few months ago:
www.linux.org/threads/open-4-konsole.6155
If you are using Konsole on a KDE desktop - You could do something like this:
Code:
echo ". ~/.profile; ~/full/path/to/your/testprogram" > /tmp/tmpTest
(konsole --separate --hold -e /bin/bash --rcfile /tmp/tmpTest) &

The echo command above writes a temporary file on /tmp/ containing a list of the commands we want to run in bash. In this case we run ". ~/.profile" to set up your bash environment, and then we include the path to the executable you want to run.
The second command opens a konsole window and executes bash using the temporary file as bash's .rcfile, causing it to load your .profile and then execute your program.
BTW: The brackets are used to enclose the entire konsole command so we can use & to run konsole as a background process in the current terminal so you can still do other things in the terminal you are running the above command in!

Or using gnome-terminal:
Code:
echo ". ~/.profile; ~/full/path/to/your/testprogram" > /tmp/tmpTest
(gnome-terminal -x /bin/bash --rcfile /tmp/tmpTest) &

If you are using another terminal you should refer to its man-page to see how to do it!

EDIT: Didn't notice GrumpyOldMan had posted while I was composing this! :/
 
Last edited:
Won't konsole automatically run the profile? I just tried running konsole out of the command line, and ran export in the new terminal - all the stuff seems there.
 
thank all, actually i'm working with ubuntu and this is a kind of homework, i don't think the command is that much long it should be an option using "./" or another common command instead of "./" to run an executable file. please forgive me if i can't make clear it enough.( i am beginner ) , Thanks
 

Staff online


Top