Operating System - HP-UX
1820330 Members
2820 Online
109623 Solutions
New Discussion юеВ

difference between "sh -c" & "/usr/bin/sh"

 
SOLVED
Go to solution
j773303
Super Advisor

difference between "sh -c" & "/usr/bin/sh"

does anyone know the difference between "sh -c" & "/usr/bin/sh"

I've a process shows as below: ps -ef

sh -c exec /etc/cmcluster/mqm/mq.cntl
Hero
4 REPLIES 4
Peter Godron
Honored Contributor
Solution

Re: difference between "sh -c" & "/usr/bin/sh"

Hi,
I believe sh -c will run the /usr/bin/sh.
Test:
$ cat a.sh
echo $PPID
sleep 10
echo $PPID

$ sh -c a.sh &
[1] 4142
$ 4142
ps -ef | grep 4142
godronpw 4143 4142 0 08:46:47 pts/ta 0:00 /usr/bin/sh a.sh
godronpw 4142 4045 0 08:46:47 pts/ta 0:00 sh -c a.sh
godronpw 4150 4045 0 08:46:53 pts/ta 0:00 grep 4142
$ 4142

rariasn
Honored Contributor

Re: difference between "sh -c" & "/usr/bin/sh"

Coolmar
Esteemed Contributor

Re: difference between "sh -c" & "/usr/bin/sh"

Hi, I found the following:

-c
Read commands from the command_string operand. Set the value of special parameter 0 (see Special Parameters) from the value of the command_name operand and the positional
parameters ($1, $2, and so on) in sequence from the remaining argument operands. No commands shall be read from the standard input.

I interpret that to say that "sh -c string" is the same as putting that string in a file and running it as a script:

# echo 'echo hello there' > test.script
# sh test.script
hello there
Bill Hassell
Honored Contributor

Re: difference between "sh -c" & "/usr/bin/sh"

sh -c is almost always initiated from a script. Look at the parent process (PPID) and you'll likely see it will be an application or cron or batch script.


Bill Hassell, sysadmin