Well, from the name 'pid.sh' I hope you know what is $$ for. But executing a shell script your shell invokes another, child shell. And this shell is just another process. And if your start another terminal you get a different $$. Or if you just execute sh (or bash, or ksh) you get a different $$ too because all these shell would be different processes.
If you have troubles with understanding "pid" you can read more here - Process identifier - Wikipedia, the free encyclopedia.
In Unix-like operating systems the current process ID is provided by a getpid() system call, or as a variable $$ in shell.
That $$ statement is incorrect, though a common misconception. In a subshell the value of $$ is not the pid of the subshell, but that of an ancestor. $$ only actually reflect's the process pid when in an invoked shell's execution environment.
Take the following command:
The first $$ will match the invoked, top-level shell's pid. The second $$ is executed in a subshell whose pid is not $$, since $$ is still that of the parent, top-level (invoked) shell. The third $$ differs from the first two since it is printed from an invoked shell which sets $$ to its own pid.
If the top-level invoked shell has a pid of 10000, and the subshell created for the command subsitution is 10001, and the shell invoked from within the subshell (sh -c ...) is 10002, the output from this command would be "10000 10000 10002".
Personally, I don't conceive of $$ as being as much about current pid as about the current, invoked shell whose execution environment is currently in charge and propagating to subshells.
In actuality, $$ could be a pid, a parent pid (subshell), a grandparent's pid (subshell within a subshell) ...
Yes, in an "inner" subshell ( in "(...)" or "$(...)" or "`...`") you get the same $$. But I'm afraid this only confuses the topic starter. You shouldn't learn to the letter "Z" not knowing "A", is not it?
I get a different output when i manually run the .sh script and when it is run by a cron job. Please help me ..
TMP1="/lhome/bbuser/script/wslog/sar.t1"
TMP2="/lhome/bbuser/script/wslog/sar.t2"
TMP3="/lhome/bbuser/script/wslog/sar.t3"
OUTPUT="/lhome/bbuser/script/wslog/sar.out"... (8 Replies)
Hi,
I'd like to redirect the STDOUT output from my script to a file and simultaneously display it at a console.
I've tried this command:
myscript.sh | tail -f
However, it doesn't end after the script finishes running
I've also tried this:
myscript.sh | tee ~/results.txt
But it writes... (3 Replies)
Hey everyone
I have a sparc enterprise T2000 I'm trying to install solaris 10 on. The only way I can connect to it is the SER MGT console, but I'm not getting anything to display (in Hyper terminal, or PUTTY) when I boot it. Upon googleing, all I get back is "No output may have been generated.... (4 Replies)
I tried several times to get answer to the below problem. Someone can please help me?
$ cat p1.sh
#!/bin/sh
`./c1.sh &`
while # indefinite loop
do
x=5;
done
$ cat c1.sh # sleep for 10 sec and exit
#!/bin/sh
sleep 10;
Execute P1 as ./p1 &
$ ps -eaf | grep c1... (1 Reply)
Hello All
Nice to meet you all here in this forum,
it's my 1rst time here
i'm asking about a little issue that i face
i added a ksh script that echo " please insert your name " and store the output to a login.log file.
the script is working fine with normal telnet
but Xstart is not working... (8 Replies)
Guys,
I do have a script that runs to take the server out from network, after running the script it is writing the new log file{outFile} in to directory . Now what i need is my script should tail the last modified file{outFile} & search the string {Server Status} ans should echo the same at the... (0 Replies)
I have the following script (MyScript):
#!/bin/sh
ps U erv | grep -v grep | grep -F "/usr/bin/collect -o 101"
echo "Result: $?"
When executed from the command line, I get
... (the line containing /usr/bin/collect -o 101)
Result: 0
(which is correct since collect is running)
When I... (4 Replies)
hi all,
I am trying to write some message to a file using the following command.
echo "${MESSAGE}" >&1 | tee -a ${File_name}
can the same be done without using echo . I don't want the result to be displayed to the console. Can anyone guide me.
Thanks in advance (6 Replies)
Hello everybody,
I am having two machines. I am using g++v2.95
When I do the build,the size of output file on both machines differ. I am not able to find what can be the problem. Both the machines are solaris 5.6
The command is :
g++ -c -g -I./ -I../../../include -I/usr/local/include/g++-3... (1 Reply)