Unable to get pid from fuser


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to get pid from fuser
# 1  
Old 07-06-2016
Oracle Unable to get pid from fuser

Code:
bash-3.2$ fuser -f  /bin/nohup.out
/bin/nohup.out:    13136o   13111o

The pid is 13136.
Can you tell me how can i extract just the pid 13136 from the above output ?

Code:
bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v

I was trying on this lines but i get strange output.
Code:
bash-3.2$ fuser -f  /bin/nohup.out |awk '{print $1}'
/bin/nohup.out: oo
13136

Can you please suggest.
# 2  
Old 07-06-2016
Why do you just want 13136? Why not 13111 as well?

Even though you should always use /usr/xpg4/bin/awk or nawk (instead of awk) on Solaris/SunOS systems, I can't imagine that awk produced the output you say it did in the script you showed us. In the pipeline you showed us, print $1 should have produced:
Code:
/bin/nohup.out:

# 3  
Old 07-06-2016
Quote:
Originally Posted by Don Cragun
Why do you just want 13136? Why not 13111 as well?

Even though you should always use /usr/xpg4/bin/awk or nawk (instead of awk) on Solaris/SunOS systems, I can't imagine that awk produced the output you say it did in the script you showed us. In the pipeline you showed us, print $1 should have produced:
Code:
/bin/nohup.out:

I tried nawk as well and it produces the same output as in OP.

I think killing 13136 kill -9 13136 should suffice inorder for us to stop the process completely / cleanly as 13136 is the parent process.

I opened a fresh putty session; still i see the same output as in the OP.

Irrespective, Any suggestions for me to try so i can just get only the pid i.e. 13136

Last edited by mohtashims; 07-06-2016 at 04:01 PM..
# 4  
Old 07-06-2016
I still do not understand your intentions.
The fuser output is in two streams, the pid goes to stdout and the type goes to stderr.
You can capture the stdout in a variable, and suppress stderr
Code:
pids=`fuser -f /bin/nohup.out 2>/dev/null`
echo $pids

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Fuser alternative OR running fuser on a script

Hi, Not sure whether there is a fuser alternative or any better way to check for file in use or not. I am wanting to check whether files are in use or not before removing them. Using fuser, the awk seems to be giving me 'weird' output not to mention that it is giving me 2 lines instead of... (0 Replies)
Discussion started by: newbie_01
0 Replies

2. Shell Programming and Scripting

[Solved] Unable to mailx new $pid for a script restart

Ill try to make this brief: I am trying to get the script below to run another script defined as BATNAM. The script runs fine, does what i designed it to do, however... I would like it to mailx the NEW $pid that was restarted. This script is supposed to go in crontab as root, and run by... (8 Replies)
Discussion started by: olyanderson
8 Replies

3. UNIX for Dummies Questions & Answers

fuser

if filename.txt is in used, exit, else continue. i tried to use fuser -c filename.txt, but returned bunch out PIDs eventhough filename.txt is not in used. any idea ? (10 Replies)
Discussion started by: tjmannonline
10 Replies

4. Shell Programming and Scripting

fuser - how to select the given PID? (awk/sed)

Hello, I'm trying to select, or well put the PID that is given by fuser to a var.. It has a wierd format and I somehow can't get it working, any awk/sed experts about? PID=`fuser $file | awk/sed....?` if ; then kill $PID fi Greetings and thanks for all your awesome help in advance! (4 Replies)
Discussion started by: TehOne
4 Replies

5. Solaris

FUSER problems

Greetings, I need help understanding why FUSER will not bring back PSID's on mounted filesystems. Is this a common error? Thanks in advance for your feedback. (11 Replies)
Discussion started by: Harleyrci
11 Replies

6. UNIX for Dummies Questions & Answers

fuser

Anyone ever use fuser, i tried this command fuser /database.bk but it only returns datbase.bk: I read some of the forums online, one of them said when he used fuser, it broke down the box, i really don't want that happen. I thought fuser is to see who is accessing that file, right? any... (8 Replies)
Discussion started by: adrianlearnpro
8 Replies

7. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

8. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

9. UNIX for Dummies Questions & Answers

Help with fuser

fuser is used to check whether a file is in use by a process or not. I was putting some information in a file via a background process and was doing a cat to see the contents. It gave me the pid of background process followed by stop. Understood only half, stopped because it was writing on it... (11 Replies)
Discussion started by: vibhor_agarwali
11 Replies

10. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies
Login or Register to Ask a Question