Mistu4u
Mistu4u

Reputation: 5416

How to know if a.sh is executing from b.sh?

I am running a script a.sh and parallelly I am executing b.sh. Now b.sh should not start executing it's business logic unless a.sh is finished. To achieve that in b.sh, I have a while loop which searches with the name a.sh in ps -ef command, but a.sh has many sleep commands, so when sleep is executing I am not seeing any result in ps -ef command for a.sh, rather the process is like sleep 60

In this scenario, what I can think of is either I set a flag in a.sh which b.sh can access somehow. But I don't know how to access such variable in b.sh because a.sh is not calling b.sh.

Or I can create a child process and give it a custom name and terminate it in the end of a.sh.

In such way, in b.sh I can search for the process with that particular name and till the time it is there I don;t start execution of the business logic in b.sh. But I don't know how to do this either.

Upvotes: 0

Views: 56

Answers (1)

Dark Sinus
Dark Sinus

Reputation: 154

Why not let the 2 communicate? For example what you could do :

  • a.sh writing into some temporary file its progress status
  • b.sh loop reading the file waiting to see the correct thing in that file to progress.

Note that there might be some easier/safer way to do that in bash (using signals maybe) but I think that should do the job. Be careful though about the concurrent aspect of your problem.

(can't comment not enough rep)

Upvotes: 1

Related Questions