Operating System - HP-UX
1751939 Members
4867 Online
108783 Solutions
New Discussion юеВ

Get Idle Time for Process not attach to TTY

 
alicehbtan
New Member

Get Idle Time for Process not attach to TTY

Can anyone teach me how to use UNIX command to get the idle time for process not attach to TTY?

I had try w but i only list the process that attach to TTY.

Thanks You.
8 REPLIES 8

Re: Get Idle Time for Process not attach to TTY

What are you trying to acheive here? There are many many processes on a UNIX system which could appear to be idle (depending on your definition of idle - I would take is as "Not clocking up CPU time"), but these processes are quite necessary and shouldn't be killed.

e.g. on most systems the process "envd" will never clock up any CPU time and could certainly be defined as "idle", but if your CRAC fails in your datacenter and the temperature starts to rise, you'll be glad you had envd running to initiate a controlled shutdown.

HTH

Duncan

I am an HPE Employee
Accept or Kudo
alicehbtan
New Member

Re: Get Idle Time for Process not attach to TTY

Hi Duncan,

Thanks for your reply.

I am running my application by thin client method, when use ps command, it will show ? in the tty column and comment is runcbl.

Now i need to know the idle time in order for me to kill the user.

Thanks You.
Dennis Handly
Acclaimed Contributor

Re: Get Idle Time for Process not attach to TTY

>I need to know the idle time in order for me to kill the user.

I don't see anything obvious.
You can look at time or pcpu and if not changing or 0 you could assume idle. Or State = "S".
alicehbtan
New Member

Re: Get Idle Time for Process not attach to TTY

Hi Dennis,

Thanks for your reply.

Can i know the command to get the information that you give me?

Thanks You.
Dennis Handly
Acclaimed Contributor

Re: Get Idle Time for Process not attach to TTY

>Can I know the command to get the information that you give me?

Sorry, these were fields of ps(1):
UNIX95=EXTENDED_PS ps -p PID -opid,pcpu,state,time,comm
alicehbtan
New Member

Re: Get Idle Time for Process not attach to TTY

Hi Dennis,

Thanks for your reply.

I need to get the command to get the idle time for me to write a program to kill the user who meet certain idle time.

Thansk You.

Re: Get Idle Time for Process not attach to TTY

There is no way to display a process idle time from a command (at least that I am aware of, and excluding those that show up in the "w" command)

You have to calculate it yourself using a script. If I understand corerctly you are only interested in processes that have no tty associated with them and are called "runcbl". Well the following should get those for you:

ps -t \? | grep [r]uncbl

Now you are interested in the third column which shows cumulative process execution time. If this is not increasing the process is "probably" idle.

So you need to write a script to save the data from the command above, sleep for an hour or so, run the command again and then compare against that data.

If the cumulative execution time isn't incrementing then the process is "probably" idle. Note I say "probably", as the process could be blocked on a read for example (waiting for input from a network socket or some other form of IPC for example). So it's up to you to be confident about what processes you can and can't then go on to kill.

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Dennis Handly
Acclaimed Contributor

Re: Get Idle Time for Process not attach to TTY

>I need to get the command to get the idle time for me to write a program

That's the problem, you need to write a program to get this info. A command isn't likely to provide enough info. This can only provide a start.
UNIX95=EXTENDED_PS ps -opid,pcpu,state,time,comm -C runcbl