The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

"sh -c exec" memory usage

asked 2014-06-29 21:47:35 +0000

anonymous user

Anonymous

So I've seen that using the i3 directive "exec" processes are launched with "sh -c", leaving the htop view full of "sh -c" commands.

I tried using bash exec by doing this:

bindsym $mod+m exec exec xterm

and the result is no more "sh -c" in the process output.

The question is: am I saving memory by doing this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-06-30 06:33:12 +0000

Adaephon gravatar image

Yes you are saving memory. By calling the command exec you are replacing sh with the command (xterm in your example). So you are saving the memory sh would use.


The question is, how much do you save?

On my system (Ubuntu 14.04, amd64) sh is a dash and needs 464 kB residential memory and about 4.5 MB virtual memory. Of course virtual memory includes shared libraries, which are only loaded once and are probably loaded anyway for some other process. So effectively I could save about 0.5 MB. At the moment I have 10 instances of sh -c running, so that would be about 5 MB. Not all that much. Even if it were 100 instances, it would still only be 50 MB. It may be a concern on very minimal or old systems with less then a gigabyte of memory, but then I don't think you'll have much success running 100 separate applications on your desktop there.

If /bin/sh is a bash, it would take about 2 MB residential memory (on my system). Granted that is quite a bit more, but still, unless you start huge amounts of programs it is unlikely to matter on a modern system.


That being said, I see no reason not to use exec exec for simple commands (only one command and its parameters). Obviously you cannot use any shell constructs that way, as the shell is replaced after the first command and any further command will never be run. (for example exec sleep 10; xclock or exec sleep 10 && xclock; both will wait for 10 seconds, but xclock will not be executed)

edit flag offensive delete link more

Comments

Understood. Thanks!

tigrezno gravatar imagetigrezno ( 2014-07-01 15:07:02 +0000 )edit

Question Tools

Stats

Asked: 2014-06-29 21:47:35 +0000

Seen: 172 times

Last updated: Jun 30 '14