Getting the process ID of the terminal in Unix/Linux


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Getting the process ID of the terminal in Unix/Linux
# 1  
Old 05-13-2012
MySQL Getting the process ID of the terminal in Unix/Linux

Hi,

How can we get the process id of the terminal we are using?

When we logged in to unix, we have an associated terminal. we can use "tty" command to get the terminal we are using like:
/dev/pts/0

I want to know the process id of this terminal. Please reply as I searched a lot but I didn't find any answer.
Thanks in advance!

Regards,
# 2  
Old 05-13-2012
Code:
echo $$

# 3  
Old 05-13-2012
Code:
[~]# ps
  PID TTY          TIME CMD
 7075 pts/1    00:00:00 bash


Last edited by Scrutinizer; 05-13-2012 at 07:59 AM.. Reason: code tags
This User Gave Thanks to gauravsharma29 For This Post:
# 4  
Old 05-13-2012
$$ stand for current shells process id, but I want to know the process id of the terminal we are currently connected to.
# 5  
Old 05-13-2012
Do you mean $PPID ?
# 6  
Old 05-13-2012
A terminal is a file. Like /dev/tty. Files do not have a process id. Rather than having us continue to guess what is going for you, please tell us what you are trying to do. Not what you think you should do.

The process that "owns" the terminal is usually called the controlling process, or more correctly, the process group leader. You already were given a way to do that - to show the pid of the process group leader
This User Gave Thanks to jim mcnamara For This Post:
# 7  
Old 05-13-2012
Just faced an question at an interview like:
How to kill the terminal you connected to?
I thought it was about killing your own session like logged in shell but the the interviewer asked me again and again the same question.
So I got confused and I searched a lot to know about it but got more confused and put the same question here to get some idea about the question. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Process on a specified Terminal and Socket Port does not start

Hi, I new to AIX, and I have been using Rocket UniData in it. I had to set up a Process for Data Exchange by assigning a unique Terminal and a Socket Port to that process. I ran the process for the first time and it was successful and after use I stopped the process. Now when I want to run it... (3 Replies)
Discussion started by: BejoyS
3 Replies

2. UNIX for Beginners Questions & Answers

Need free Linux / UNIX Terminal over Internet

I do not wish to install Unix or Linux locally be it on my system or my Virtual box. I am looking for an online free Linux / Unix Terminal that i can connect and use. Something like ... Unix Terminal Online But the problem with Unix Terminal Online] is that i CANNOT ping it's ip which i... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. Shell Programming and Scripting

need to extract terminal from this process -perl regx

Hi All, i ve a process, user4 31779 2836 0 01:43 pts/6 00:00:00 sh /home/user/DATE/SUT_SCR/c.sh like this i'll get so many process when in run ps -ef | grep pts | grep c.sh i need to extract terminal id from this string. i.e pts/6, or sometimes pts/22 same way i need to do for... (3 Replies)
Discussion started by: asak
3 Replies

4. Solaris

Start process independent from TERMINAL (or also with PPID 1)

Hi *, please, I need fast tip (help). I have a process starting through /etc/rc3.d/xxxx script. However, sometimes (mostly because of testing reasons) I need to stop the process, change something and then start it again. But: 1) when I start it in terminal, the process dies when I leave the... (2 Replies)
Discussion started by: freeangel
2 Replies

5. Shell Programming and Scripting

Process not attached to terminal

Hi Folks, When i try to run schedule job on Unix server am getting following errror messges in logs pic_selection @starting on Fri Feb 5 01:53:06 GMT 2010 ------------------------------------------------------------------------------- Microfocus Cobol batch run Started: Fri Feb 5... (4 Replies)
Discussion started by: bhargav20
4 Replies

6. UNIX for Advanced & Expert Users

Control process from different terminal (over SSH)

I pressed CTRL Z and suspended the job. then I pressed bg, The process re-started to throw output on the terminal and its not allowing me to access the prompt. its not even accepting CTRL Z. The process has been running for about 2 hours now and I want to suspend it by opening another terminal.... (3 Replies)
Discussion started by: rakeshou
3 Replies

7. UNIX for Advanced & Expert Users

how to run a process after closing the terminal

i want to execute a shell script even if the terminal is closed. how to do? (3 Replies)
Discussion started by: lakshmananindia
3 Replies

8. UNIX for Dummies Questions & Answers

upper limit of accessible memory space for a single process in Unix/Linux

Hellp all, if there is 3G memory in my Unix server I want to know if all the 3G space can be used by ong sigle process. As i know, in Windows, one process can only access at most 1G memory despite there is probably more than 1G memory is equipped. (1 Reply)
Discussion started by: cy163
1 Replies

9. Shell Programming and Scripting

Start process in shellscript at other terminal

A programming running in tty0 crashes. In a second terminal I kill all the processes. Can i start the program again from this terminal? Yes, I can, but it starts in tty1, and when i close the terminal, the program closes. Now I want to start the program from tty1 in tty0, so i can close... (4 Replies)
Discussion started by: benschell
4 Replies

10. UNIX for Advanced & Expert Users

connecting to unix through hyper terminal - as a dumb terminal

I just changed from windows NT to XP and I am no longer able to connect to my unix system. I used to use hyper terminal -- which acts as dumb terminal to my main frame unix system. I think one of the options used to be "direct to comX". This option isn't listed now. I use a serial port and the... (2 Replies)
Discussion started by: michelle
2 Replies
Login or Register to Ask a Question