I was trying to change the msg_max queue size on my ubuntu 14.04 system. Here is the console output:
$ sudo echo 500 > /proc/sys/fs/mqueue/msg_max
-bash: /proc/sys/fs/mqueue/msg_max: Permission denied
$
$ cat /proc/sys/fs/mqueue/msg_max
1000
$ sudo echo 500 > /proc/sys/fs/mqueue/msg_max
-bash: /proc/sys/fs/mqueue/msg_max: Permission denied
$ sudo sh -c "echo 500 > /proc/sys/fs/mqueue/msg_max"
[sudo] password for XXX:
$ cat /proc/sys/fs/mqueue/msg_max
500
My question is why the first approach using echo directly is not working while the other one using sh -c works?