Customized command excution

Hi,

The below commands will be inside a KSH script and SOLARIS machine.

Command-1 //Executes in 10s,5s,..5mins,etc
TIMER  = Look for Command-1 execution status - IF finished in 25secs move to next command in the script IF NOT kill above command and move to next  command.
Command-2 

Any suggestions

Try

command-1 &
sleep 25
kill $!
command-2

If you want to eliminate the remote chance that command-1's PID ($!) has been reused in between, you may want to insert some process/command check before killing.

2 Likes

I guess this should be working fine.

In a shell with job control you can do

kill %1

and a reused PID won't be killed.

There is no way that a Solaris system is going to recycle a PID in 30 seconds unless someone has changed the system's maximum PID to be artificially low to make it happen.

Based on what configuration/setting the PID's are recycled in solaris and in other machines.
What will be the maximum time i can expect for some other process to use same PID?

It isn't a question of time; it is a question of how many processes you are starting and how many are running at once.

When you boot the system, init becomes the 1st process started and it gets PID 1. The next process started gets PID 2, ... This continues until a process is assigned the highest PID the system will use (let's call it PID_MAX). Once that happens, it will start assigning PIDs in a loop again starting with 1 (but it will not assign a new process a PID that is still in use by an unreaped zombie or a by running process). I don't remember if Solaris actually has a kernel parameter named PID_MAX nor what its value is if it does exist, but the concept still applies. I would expect PID_MAX to be similar in range to INT_MAX (i.e., 2,147,483,647) on 64-bit hardware. On any Solaris system I've seen, you won't have a billion active processes and you won't be able to exec a billion processes in a minute (let alone 25 seconds); so you don't stand much of a chance of recycling a PID in this application.

On the other hand, if you have a process that may be running for weeks that spawns children on a system that may run for months between reboots, PID recycling should be considered.

1 Like

Solaris has pidmax (number of PIDs) and max_nproc (total number of processes). Both default to 30000, are tunable in /etc/system, where maximum is 999999 and max_nproc<=pidmax.
Unlike Linux, the LWPs (threads) have extra IDs i.e. are not taken from the PID pool.

Good idea, but there may be several background jobs - use %% , %+ , %command-1 , or % instead.

Thanks Don and others !! These information will be of great use to everyone.