Difference between pages "Bg, fg and jobs" and "Find out where configuration changes are stored"

From Linuxintro
(Difference between pages)
imported>ThorstenStaerk
 
 
Line 1: Line 1:
bg, fg and jobs are [[process]] related [[commands]] that belong together. bg stands for background and fg stands for foreground.
+
Whenever I set up a computer, I start konsole and change its settings. I choose Settings -> Configure Current Profile -> Tabs -> "Show 'New Tab' and 'Close Tab' buttons in tab bar". Today I wanted to write a script to do this configuration change for me. The most important question is - where is this setting being saved?
  
= Concept =
+
I could find this out using the command
When you start a [[program]] under Linux, by default the command runs in the foreground. This means the console is reserved for in- and output to and from this program. You do not get a prompt while the program is running. Here is an example for this showing the program xclock being called by the command
+
strace -ffe open konsole
  xclock
+
[[strace]] is a cool [[command]] that shows you every syscall invoked by a program (in the above case konsole). When called with the -e open argument, it will only show the open syscalls. This gives you a powerful tool into your hands: A monitor which files are read and/or modified by a program. The output will read like this:
 +
[pid 29951] open("/etc/localtime", O_RDONLY) = 3
 +
[pid 29951] open("/etc/kde4rc", O_RDONLY|O_CLOEXEC) = 3
 +
  [pid 29951] open("/root/.kde4/share/config/kdeglobals", O_RDONLY|O_CLOEXEC) = 3
 +
The -ff argument is needed so strace still follows spawning processes; for more information, read [http://man-wiki.net/index.php/1:strace strace's man page].
  
[[File:Snapshot-fg-xclock.png]]
+
So I did [[open a console]], entered
 +
strace -ffe open konsole
 +
A konsole window popped up and I chose Settings -> Configure Current Profile -> Tabs -> "Show 'New Tab' and 'Close Tab' buttons in tab bar". When I clicked on "Apply", I found a line saying
 +
[pid 29951] open("/root/.kde4/share/apps/konsole/Shell.profile", O_RDONLY|O_CLOEXEC) = 16
 +
And I could verify my changes go to /root/.kde4/share/apps/konsole/Shell.profile:
 +
# [[cat]] /root/.kde4/share/apps/konsole/Shell.profile
 +
[...]
 +
ShowNewAndCloseTabButtons=false
 +
[...]
  
This program runs in the foreground, the console is reserved for its in- and output. To run the same program in the background, start it with the ampersand ("&") after the program name:
+
[[Category:Geeky]]
xclock &
 
 
 
[[File:Snapshot-bg-xclock.png]]
 
 
 
In this case you can continue to call further [[commands]] on the console.
 
 
 
= Hints =
 
Maybe you have started a program without the & behind it, and now you want to use console to issue further commands. In this case stop the program using CTRL_Z:
 
tweedleburg:~ # xclock
 
^Z
 
[1]+  Stopped                xclock
 
List it using the command jobs
 
tweedleburg:~ # jobs
 
[1]+  Stopped                xclock
 
And send it to the background using the command bg
 
tweedleburg:~ # bg
 
[1]+ xclock &
 
tweedleburg:~ #
 
Now it will be as if you had called the command with the & behind it. You will be able to use console for issueing further commands.
 
 
 
= See also =
 
* [[disown]]
 

Revision as of 09:33, 22 December 2011

Whenever I set up a computer, I start konsole and change its settings. I choose Settings -> Configure Current Profile -> Tabs -> "Show 'New Tab' and 'Close Tab' buttons in tab bar". Today I wanted to write a script to do this configuration change for me. The most important question is - where is this setting being saved?

I could find this out using the command

strace -ffe open konsole

strace is a cool command that shows you every syscall invoked by a program (in the above case konsole). When called with the -e open argument, it will only show the open syscalls. This gives you a powerful tool into your hands: A monitor which files are read and/or modified by a program. The output will read like this:

[pid 29951] open("/etc/localtime", O_RDONLY) = 3
[pid 29951] open("/etc/kde4rc", O_RDONLY|O_CLOEXEC) = 3
[pid 29951] open("/root/.kde4/share/config/kdeglobals", O_RDONLY|O_CLOEXEC) = 3

The -ff argument is needed so strace still follows spawning processes; for more information, read strace's man page.

So I did open a console, entered

strace -ffe open konsole

A konsole window popped up and I chose Settings -> Configure Current Profile -> Tabs -> "Show 'New Tab' and 'Close Tab' buttons in tab bar". When I clicked on "Apply", I found a line saying

[pid 29951] open("/root/.kde4/share/apps/konsole/Shell.profile", O_RDONLY|O_CLOEXEC) = 16

And I could verify my changes go to /root/.kde4/share/apps/konsole/Shell.profile:

# cat /root/.kde4/share/apps/konsole/Shell.profile 
[...]
ShowNewAndCloseTabButtons=false
[...]